P1664 Feel Good With Daily Check-in
Background
On Luogu, checking in is not just a simple mouse click. By checking in every day on Luogu, you can clearly record your learning footprint on Luogu. By checking in daily, you keep reminding yourself: I studied on Luogu for another day, which helps cultivate perseverance, patience, and carefulness. In addition, by checking in, you can gain experience points as rewards; the amount of experience points reflects your seniority and achievements on Luogu to some extent. By accumulating activity points from check-ins and leveling up gradually, you will feel “closer and closer to the gods.”
Description
Luogu’s check-in system is similar to other websites: the more consecutive days you check in, the more rewards you get each time, and the consecutive days increase by one. However, on other websites, if you miss a day, your consecutive days reset to zero. Unlike other websites, Luogu is more user-friendly: if you miss multiple days, your consecutive days only decrease, and the fewer the missed days, the fewer days are deducted. The rule is to reduce by $2^{n-1}$ days, where $n$ is the number of consecutively missed days. The streak is settled at the next check-in, and the streak will not go below $0$. In other words, if you check in every other day, the streak will remain unchanged.
When the streak reaches the following lengths, different activity point rewards are given:
$1$ day: reward $1$ (A journey of a thousand miles begins with a single step).
$3$ days: reward $2$ (You’ve kept it up for $3$ days, keep going!).
$7$ days: reward $3$ (The weekly cycle).
$30$ days: reward $4$ (From full moon to crescent, habits are formed).
$120$ days: reward $5$ (You’ve persisted for four months!).
$365$ days: reward $6$ (You kept it up for all four seasons! Not easy!).
Xiao A registered a Luogu account $N$ days ago. Although he vowed to check in every day, he found it hard to keep. Now that we know his check-in record for $N$ days, Xiao A wants to know how many activity points he can obtain from check-ins in $N$ days.
Input Format
The first line contains an integer $N$.
The next $N$ lines each contain an integer $1$ or $0$, indicating whether he checked in on that day.
Output Format
Output a single integer, the total activity points obtained.
Explanation/Hint
Day $1$: $1$ // Start checking in! Gain $1$ activity point, total $1$, streak $1$ day.
Day $2$: $1$ // Gain $1$ activity point, total $2$, streak $2$ days.
Day $3$: $1$ // Gain $2$ activity points, total $4$, streak $3$ days.
Day $4$: $1$ // Gain $2$ activity points, total $6$, streak $4$ days.
Day $5$: $1$ // Gain $2$ activity points, total $8$, streak $5$ days.
Day $6$: $0$ // Going to Mars, no internet, had to miss a check-in.
Day $7$: $0$.
Day $8$: $0$.
Day $9$: $1$ // I’m back, but unfortunately the streak became $5-4=1$ day... TQT... Gain $1$ activity point, total $9$, streak $2$ days.
Day $10$: $0$ // Ah, too many things to do, forgot it.
Day $11$: $1$ // Streak became $2-1=1$ day. Gain $1$ activity point, total $10$, streak $2$ days.
Day $12$: $1$ // Gain $2$ activity points, total $12$, streak $3$ days.
Xiao A: How about making an automatic check-in machine?
kkksc03: That does not comply with Luogu’s rules!
Constraints: $1 \leq N \leq 10^3$.
Translated by ChatGPT 5