CSES - HIIT Open 2019 - Results
Submission details
Task:Bit Strings
Sender:bigint bugaa
Submission time:2019-05-25 11:55:42 +0300
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.03 sdetails
#3ACCEPTED0.04 sdetails
#4ACCEPTED0.04 sdetails
#5ACCEPTED0.03 sdetails
#6ACCEPTED0.04 sdetails
#70.04 sdetails
#80.04 sdetails
#9ACCEPTED0.03 sdetails
#10ACCEPTED0.04 sdetails
#110.05 sdetails
#120.06 sdetails
#130.05 sdetails
#140.06 sdetails
#150.05 sdetails
#160.05 sdetails
#170.05 sdetails
#18ACCEPTED0.04 sdetails

Code

#include <iostream>
using namespace std;
using ll = long long;

const int N = 1e6 + 5;
const int M = 1e9 + 7;

ll pow[N];
ll g[N];
ll f[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
        ll n, k;
        cin >> n >> k;
        pow[0] = 1;
        for(int i = 1; i < N; ++i) {
            pow[i] = pow[i-1]*2;
            pow[i] %= M;
        }
        g[0] = 0;
        for(int i = 1; i <= n; ++i) {
            //Calc g[i]
            if(i - k + 1 < 3) {
                g[i] = 0;
            } else {
                g[i] = 2*g[i] + f[i - k];
            }
            g[i] += M;
            g[i] %= M;
            //Calc f[i]
            if(i < k) {
                f[i] = pow[i];
                continue;
            }
            if(i == k) {
                f[i] = pow[i] - 1;
                continue;
            }
            f[i] = pow[i] - pow[i - k] - pow[i-k-1] - g[i];
            f[i] += M;
            f[i] %= M;
            
        }
        if(f[n] < 0) f[n] += M;
        cout << f[n] << "\n";
        
}

Test details

Test 1

Verdict: ACCEPTED

input
1 1

correct output
1

user output
1

Test 2

Verdict: ACCEPTED

input
2 1

correct output
1

user output
1

Test 3

Verdict: ACCEPTED

input
2 2

correct output
3

user output
3

Test 4

Verdict: ACCEPTED

input
3 1

correct output
1

user output
1

Test 5

Verdict: ACCEPTED

input
3 2

correct output
5

user output
5

Test 6

Verdict: ACCEPTED

input
3 3

correct output
7

user output
7

Test 7

Verdict:

input
4 1

correct output
1

user output
3

Test 8

Verdict:

input
4 2

correct output
8

user output
7

Test 9

Verdict: ACCEPTED

input
4 3

correct output
13

user output
13

Test 10

Verdict: ACCEPTED

input
4 4

correct output
15

user output
15

Test 11

Verdict:

input
654321 123456

correct output
796245691

user output
385390876

Test 12

Verdict:

input
1000000 1

correct output
1

user output
872507016

Test 13

Verdict:

input
1000000 10

correct output
256933600

user output
305200492

Test 14

Verdict:

input
1000000 100

correct output
142013415

user output
269960075

Test 15

Verdict:

input
1000000 1000

correct output
899626120

user output
250958877

Test 16

Verdict:

input
1000000 10000

correct output
374265948

user output
485715807

Test 17

Verdict:

input
1000000 100000

correct output
388134512

user output
748653893

Test 18

Verdict: ACCEPTED

input
1000000 1000000

correct output
235042058

user output
235042058