CSES - HIIT Open 2019 - Results
Submission details
Task:Bit Strings
Sender:Varokaa J:tä
Submission time:2019-05-25 12:10:37 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.03 sdetails
#2ACCEPTED0.02 sdetails
#3ACCEPTED0.01 sdetails
#4ACCEPTED0.02 sdetails
#5ACCEPTED0.01 sdetails
#6ACCEPTED0.02 sdetails
#7ACCEPTED0.02 sdetails
#8ACCEPTED0.03 sdetails
#9ACCEPTED0.03 sdetails
#10ACCEPTED0.01 sdetails
#11ACCEPTED0.06 sdetails
#12ACCEPTED0.04 sdetails
#13ACCEPTED0.04 sdetails
#14ACCEPTED0.03 sdetails
#15ACCEPTED0.04 sdetails
#16ACCEPTED0.04 sdetails
#17ACCEPTED0.05 sdetails
#18ACCEPTED0.01 sdetails

Code

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
constexpr ll mod = 1e9+7;
ll sums[10001000];
ll get(int i) {
if (i < 0) return 0;
return sums[i];
}
ll mpow(ll b, ll e) {
if (e == 0) return 1;
if (e == 1) return b;
if (e % 2 == 0) {
ll p = mpow(b, e/2);
return (p * p) % mod;
}
return (b * mpow(b, e-1)) % mod;
}
int main() {
cin.sync_with_stdio(false);
cin.tie(nullptr);
ll n, k;
cin >> n >> k;
if (n == k) {
cout << (mpow(2, n) + mod - 1) % mod << endl;
return 0;
}
for (ll i = 1; i < k; i++) {
sums[i] = (get(i-1) + mpow(2, i)) % mod;
}
sums[k] = (get(k-1) + mpow(2, k) + mod - 1) % mod;
//for (int i = 0; i <= n; i++) cerr << sums[i] << " ";
//cout<<endl;
for (ll i = k+1; i <= n; i++) {
sums[i] = (get(i-1) + get(i-1) - get(i-k-1) + mod) % mod;
}
//for (int i = 0; i <= n; i++) cerr << sums[i] << " ";
cout << (get(n) - get(n-1) + mod) % mod << endl;
/*
ll n, k;
cin >> n >> k;
ll res = 0;
for (ll i = 0; i < (1<<n); i++) {
for (int j = 0; j <= n-k; j++) {
if (!((i >> j) & ((1 << k) - 1))) goto skip;
}
res++;
skip:;
}
cout << res << endl;*/
}

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: ACCEPTED

input
4 1

correct output
1

user output
1

Test 8

Verdict: ACCEPTED

input
4 2

correct output
8

user output
8

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: ACCEPTED

input
654321 123456

correct output
796245691

user output
796245691

Test 12

Verdict: ACCEPTED

input
1000000 1

correct output
1

user output
1

Test 13

Verdict: ACCEPTED

input
1000000 10

correct output
256933600

user output
256933600

Test 14

Verdict: ACCEPTED

input
1000000 100

correct output
142013415

user output
142013415

Test 15

Verdict: ACCEPTED

input
1000000 1000

correct output
899626120

user output
899626120

Test 16

Verdict: ACCEPTED

input
1000000 10000

correct output
374265948

user output
374265948

Test 17

Verdict: ACCEPTED

input
1000000 100000

correct output
388134512

user output
388134512

Test 18

Verdict: ACCEPTED

input
1000000 1000000

correct output
235042058

user output
235042058