#P16291. [蓝桥杯 2026 省 Java A 组] 连续打卡

    ID: 18306 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>模拟字符串2026蓝桥杯省赛

[蓝桥杯 2026 省 Java A 组] 连续打卡

Problem Description

Xiaoming is a self-disciplined programmer. He uses a learning check-in app every day to record his study progress. The app records the date of each check-in. Now Xiaoming wants to find his longest streak of consecutive check-in days.

A consecutive check-in means that there is a check-in record on every day within a continuous range of days. For example, if Xiaoming checked in on 2026-01-01, 2026-01-02, and 2026-01-03, then this is a streak of 33 consecutive days.

Given Xiaoming's check-in records (a number of dates), compute the maximum number of consecutive check-in days.

Note: If none of the check-in dates are adjacent, then the longest consecutive check-in days is 11. That is, a single day is also considered a streak of 11 day.

Note: The check-in records may contain duplicates (multiple check-ins on the same day). Multiple check-ins on the same day count as one day only.

Input Format

The first line contains an integer NN, representing the number of check-in records.

The next NN lines each contain a date in the format YYYY-MM-DD (year-month-day).

Output Format

Output one integer, representing the maximum number of consecutive check-in days.

7
2026-01-01
2026-01-02
2026-01-03
2026-01-05
2026-01-06
2026-01-10
2026-01-02
3
5
2025-12-30
2025-12-31
2026-01-01
2026-01-02
2026-01-03
5

Hint

Sample Explanation 1

After removing duplicates, Xiaoming's check-in dates are: 2026-01-01, 2026-01-02, 2026-01-03, 2026-01-05, 2026-01-06, 2026-01-10.

Among them:

  • 2026-01-01 to 2026-01-03 are 33 consecutive days.
  • 2026-01-05 to 2026-01-06 are 22 consecutive days.
  • 2026-01-10 is a single streak of 11 day.

Therefore, the longest consecutive check-in days is 33.

Sample Explanation 2

These 55 days are consecutive dates across two years, from December 30, 2025 to January 3, 2026, for a total of 55 consecutive check-in days.

Constraints and Evaluation Rules

For all testdata:

  • 1N1000001 \le N \le 100000.
  • Date range: 2000-01-01 to 2099-12-31.
  • All dates are guaranteed to be valid (including leap years).
  • Dates may be given in any order and may contain duplicates.
Testdata Percentage Data Size
30% 1N1001 \le N \le 100
60% 1N100001 \le N \le 10000
100% 1N1000001 \le N \le 100000

Translated by ChatGPT 5