Task: | Bit Strings |
Sender: | Barely div 1 |
Submission time: | 2019-05-25 14:18:55 +0300 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.03 s | details |
#2 | ACCEPTED | 0.02 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.02 s | details |
#5 | ACCEPTED | 0.06 s | details |
#6 | ACCEPTED | 0.05 s | details |
#7 | ACCEPTED | 0.02 s | details |
#8 | ACCEPTED | 0.05 s | details |
#9 | ACCEPTED | 0.05 s | details |
#10 | ACCEPTED | 0.06 s | details |
#11 | ACCEPTED | 0.09 s | details |
#12 | ACCEPTED | 0.01 s | details |
#13 | ACCEPTED | 0.10 s | details |
#14 | ACCEPTED | 0.11 s | details |
#15 | ACCEPTED | 0.10 s | details |
#16 | ACCEPTED | 0.11 s | details |
#17 | ACCEPTED | 0.12 s | details |
#18 | ACCEPTED | 0.12 s | details |
Code
#include <vector> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; vector<LL> cumsum { }; vector<LL> pows { }; vector<LL> nums { }; LL MOD = 1000000007; int n,k; LL norm(LL num) { while (num < 0) { num += MOD; } num = num % MOD; return num; } LL secondpow(LL pow) { if (pows.size() == 0) { pows.emplace_back(1); for (int i =0; i < 1000001; i++) { pows.emplace_back(norm(pows.back() * 2)); } } return pows[pow]; } int main() { cin >> n>>k; if (k == 1) { cout << 1 << endl; return 0; } for (int i = 0; i < k; i++) { LL cur = secondpow(i); nums.emplace_back(cur); } cumsum = { 1 }; for (int i = 1; i < k; i++) { LL ans = nums[i] + cumsum[i - 1]; cumsum.emplace_back(norm(ans)); } //for (int i = 0; i < nums.size(); i++) cout << nums[i] << " "; cout<<endl; //for (int i = 0; i < nums.size(); i++) cout << cumsum[i] << " "; cout<<endl; for (int i = k; i < n; i++) { LL previtem = (i == k) ? 0 : cumsum[i-k-1]; LL newnum = cumsum.back() - previtem; nums.emplace_back(norm(newnum)); LL newcumsum = norm(cumsum.back() + newnum); cumsum.emplace_back(newcumsum); } //for (int i = 0; i < nums.size(); i++) cout << nums[i] << " "; cout<<endl; //for (int i = 0; i < nums.size(); i++) cout << cumsum[i] << " "; cout<<endl; LL tmp = norm(secondpow(n) - nums.back()); for (int i = nums.size() - k; i < n - 1; i++) { tmp = norm(tmp - nums[i]); } cout << norm(secondpow(n) - tmp); }
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 |