#P1664. Luogu Check-in Active Value Calculation
Luogu Check-in Active Value Calculation
Luogu Check-in Active Value Calculation
Luogu's daily check-in system rewards users based on their consecutive check-in days. Unlike other sites where a single missed day resets the streak to zero, Luogu reduces the consecutive count by a penalty when users miss one or more days. The penalty is defined as \(2^{n-1}\) days where \(n\) is the number of consecutive days missed. When a user next checks in, the current consecutive count is reduced by this penalty (but not below \(0\)) and then increased by \(1\) for the current check-in.
For example, if a user checks in one day and then misses one day before checking in again, the penalty will be \(2^{1-1} = 1\) day. Thus, if the user’s previous consecutive count was \(c\), the new count will be \(\max(c - 1, 0) + 1\). Hence, if someone checks in every other day, the consecutive count remains constant.
Additionally, when the consecutive count exactly reaches certain thresholds, the user is awarded an active value bonus as follows:
- 1 day: reward 1
- 3 days: reward 2
- 7 days: reward 3
- 30 days: reward 4
- 120 days: reward 5
- 365 days: reward 6
Given the check-in record for the past N days (since registration), calculate the total active value obtained by the user.
inputFormat
The input consists of two lines:
- The first line contains a positive integer \(N\) (the number of days).
- The second line is a string of length \(N\) composed only of the characters '1' and '0', where '1' indicates that the user checked in on that day and '0' indicates they did not.
outputFormat
Output a single integer representing the total active value bonus earned.
sample
3
101
2