Task: | Bittilista |
Sender: | |
Submission time: | 2015-12-06 17:58:55 +0200 |
Language: | C++ |
Status: | READY |
Result: | 100 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 17 |
#2 | ACCEPTED | 28 |
#3 | ACCEPTED | 55 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.05 s | 1 | details |
#2 | ACCEPTED | 0.06 s | 1 | details |
#3 | ACCEPTED | 0.06 s | 1 | details |
#4 | ACCEPTED | 0.05 s | 1 | details |
#5 | ACCEPTED | 0.06 s | 1 | details |
#6 | ACCEPTED | 0.05 s | 2 | details |
#7 | ACCEPTED | 0.06 s | 2 | details |
#8 | ACCEPTED | 0.05 s | 2 | details |
#9 | ACCEPTED | 0.06 s | 2 | details |
#10 | ACCEPTED | 0.06 s | 2 | details |
#11 | ACCEPTED | 0.06 s | 3 | details |
#12 | ACCEPTED | 0.05 s | 3 | details |
#13 | ACCEPTED | 0.06 s | 3 | details |
#14 | ACCEPTED | 0.06 s | 3 | details |
#15 | ACCEPTED | 0.05 s | 3 | details |
Code
#include <iostream> #include <vector> #include <string> #include <utility> using namespace std; typedef long long LL; LL DP[60][2][120]; LL count(LL L, LL b, LL d){ if(DP[L][b][d + 60] == -1){ if(b == 1) DP[L][b][d + 60] = count(L-1,1,d) + count(L-1,0,d-1); else DP[L][b][d + 60] = count(L-1,0,d) + count(L-1,1,d+1); } return DP[L][b][d + 60]; } int main(){ for(int i = 0; i < 60; i++) for(int j = 0; j < 2; j++) for(int k = 0; k < 120; k++) DP[i][j][k] = -1; for(int i = 0; i < 120; i++) DP[1][0][i] = 0; for(int i = 0; i < 120; i++) DP[1][1][i] = 0; DP[1][0][0 + 60] = 1; DP[1][1][0 + 60] = 1; //cout << "total: " << count(6,0,0) << " " << count(5,0,-1) << " " << count(3,0,0) << endl; //return 0; LL n, k; cin >> n >> k; // 10 -> + // 01 -> - string s = ""; LL balance = 0; LL skipped = 0; if(count(n, 0, 0) >= k){ s += '0'; } else{ s += '1'; skipped += count(n, 0, 0); } for(int i = 1; i < n; i++){ //cout << skipped << " " << balance << " " << s << endl; if(s.back() == '0'){ if(skipped + count(n-i,0,-balance) >= k){ s += '0'; } else{ s += '1'; skipped += count(n-i,0,-balance); balance--; } } else if(s.back() == '1'){ if(skipped + count(n-i,0,-(balance+1)) >= k){ s += '0'; balance++; } else{ s += '1'; skipped += count(n-i,0,-(balance+1)); } } } cout << s << endl; }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
10 54 |
correct output |
---|
0001101010 |
user output |
---|
0001101010 |
Test 2
Group: 1
Verdict: ACCEPTED
input |
---|
10 302 |
correct output |
---|
1001011011 |
user output |
---|
1001011011 |
Test 3
Group: 1
Verdict: ACCEPTED
input |
---|
10 241 |
correct output |
---|
0111100000 |
user output |
---|
0111100000 |
Test 4
Group: 1
Verdict: ACCEPTED
input |
---|
10 382 |
correct output |
---|
1011111011 |
user output |
---|
1011111011 |
Test 5
Group: 1
Verdict: ACCEPTED
input |
---|
10 138 |
correct output |
---|
0100010010 |
user output |
---|
0100010010 |
Test 6
Group: 2
Verdict: ACCEPTED
input |
---|
20 131002 |
correct output |
---|
00111111111101110010 |
user output |
---|
00111111111101110010 |
Test 7
Group: 2
Verdict: ACCEPTED
input |
---|
20 441567 |
correct output |
---|
11010111100110111101 |
user output |
---|
11010111100110111101 |
Test 8
Group: 2
Verdict: ACCEPTED
input |
---|
20 109770 |
correct output |
---|
00110101100110010010 |
user output |
---|
00110101100110010010 |
Test 9
Group: 2
Verdict: ACCEPTED
input |
---|
20 327308 |
correct output |
---|
10011111110100010111 |
user output |
---|
10011111110100010111 |
Test 10
Group: 2
Verdict: ACCEPTED
input |
---|
20 302918 |
correct output |
---|
10010011111010001011 |
user output |
---|
10010011111010001011 |
Test 11
Group: 3
Verdict: ACCEPTED
input |
---|
50 216967103451763 |
correct output |
---|
011000101010101001001011100100... |
user output |
---|
011000101010101001001011100100... |
Test 12
Group: 3
Verdict: ACCEPTED
input |
---|
50 236618662270629 |
correct output |
---|
011010111001101000001001101001... |
user output |
---|
011010111001101000001001101001... |
Test 13
Group: 3
Verdict: ACCEPTED
input |
---|
50 426560943304480 |
correct output |
---|
110000011111101000111010110000... |
user output |
---|
110000011111101000111010110000... |
Test 14
Group: 3
Verdict: ACCEPTED
input |
---|
50 294553802415801 |
correct output |
---|
100001011111001010010011011000... |
user output |
---|
100001011111001010010011011000... |
Test 15
Group: 3
Verdict: ACCEPTED
input |
---|
50 502225394100883 |
correct output |
---|
111001000110001010111011000110... |
user output |
---|
111001000110001010111011000110... |