# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
117675 |
2019-06-17T05:54:25 Z |
송준혁(#2882) |
Ljetopica (COI19_ljetopica) |
C++14 |
|
71 ms |
22264 KB |
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pii;
int N, K;
int P[1010], now[1010];
int A[1010], B[1010];
LL C[1010][1010];
LL D1[1010][1010];
LL D2[1010][1010];
bool chk1[1010][1010];
bool chk2[1010][1010];
LL twoPow[1010], ans;
LL comb(int n, int r){
if (n < r || r < 0) return 0;
if (n == r || r == 0) return 1;
if (C[n][r]) return C[n][r];
return C[n][r] = (comb(n-1, r-1) + comb(n-1, r)) % MOD;
}
pii f1(int lv, int k, bool l, bool r){
if (l && now[lv] < A[lv]) return pii(0, 0);
if (now[lv] > A[lv]) l = false;
if (r && now[lv] > B[lv]) return pii(0, 0);
if (now[lv] < B[lv]) r = false;
if (lv >= N){
if (k == K) return pii(0, 1);
return pii(0, 0);
}
if (!l && !r && chk1[lv][k]) return pii(D1[lv][k], comb(N-lv, K-k));
LL t = 0;
pii ret1, ret2;
now[lv+1] = P[lv+1] ^ ((K-k) & 1);
ret1 = f1(lv+1, k, l, r);
now[lv+1] = P[lv+1] ^ ((K-k-1) & 1);
ret2 = f1(lv+1, k+1, l, r);
if (P[lv+1] ^ ((K-k) & 1)) t = (t + ret1.second * twoPow[N-lv-1]) % MOD;
else t = (t + ret2.second * twoPow[N-lv-1]) % MOD;
t = (t + ret1.first + ret2.first) % MOD;
if (!l && !r){
chk1[lv][k] = true;
D1[lv][k] = t;
}
return pii(t, (ret1.second + ret2.second)%MOD);
}
pii f2(int lv, int k, bool l, bool r){
if (l && now[lv] < A[lv]) return pii(0, 0);
if (now[lv] > A[lv]) l = false;
if (r && now[lv] > B[lv]) return pii(0, 0);
if (now[lv] < B[lv]) r = false;
if (lv >= N){
if (k == K) return pii(0, 1);
return pii(0, 0);
}
if (!l && !r && chk2[lv][k]) return pii(D2[lv][k], comb(N-lv, K-k));
LL t = 0;
pii ret1, ret2;
now[lv+1] = P[lv+1] ^ ((K-k-1) & 1);
ret1 = f2(lv+1, k, l, r);
now[lv+1] = P[lv+1] ^ ((K-k) & 1);
ret2 = f2(lv+1, k+1, l, r);
if (P[lv+1] ^ ((K-k-1) & 1)) t = (t + ret1.second * twoPow[N-lv-1]) % MOD;
else t = (t + ret2.second * twoPow[N-lv-1]) % MOD;
t = (t + ret1.first + ret2.first) % MOD;
if (!l && !r){
chk2[lv][k] = true;
D2[lv][k] = t;
}
return pii(t, (ret1.second + ret2.second) % MOD);
}
int main(){
char ch;
scanf("%d %d", &N, &K);
for (int i=2; i<=N; i++){
scanf(" %c", &ch);
if (ch == 'R') P[i] = 1;
}
for (int i=1; i<=N; i++) scanf("%1d", &A[i]);
for (int i=1; i<=N; i++) scanf("%1d", &B[i]);
twoPow[0] = 1;
for (int i=1; i<=N; i++) twoPow[i] = (twoPow[i-1] * 2) % MOD;
now[1] = 1;
pii ret1 = f1(1, 0, true, true);
pii ret2 = f2(1, 0, true, true);
printf("%lld\n", (ret1.first + ret1.second*twoPow[N-1] + ret2.first + ret2.second*twoPow[N-1]) % MOD);
return 0;
}
Compilation message
ljetopica.cpp: In function 'int main()':
ljetopica.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &K);
~~~~~^~~~~~~~~~~~~~~~~
ljetopica.cpp:82:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c", &ch);
~~~~~^~~~~~~~~~~~
ljetopica.cpp:85:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=N; i++) scanf("%1d", &A[i]);
~~~~~^~~~~~~~~~~~~~
ljetopica.cpp:86:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=N; i++) scanf("%1d", &B[i]);
~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
10872 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
512 KB |
Output is correct |
5 |
Correct |
2 ms |
508 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
640 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
2 ms |
640 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
2 ms |
512 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
22136 KB |
Output is correct |
2 |
Correct |
71 ms |
22020 KB |
Output is correct |
3 |
Correct |
70 ms |
22264 KB |
Output is correct |
4 |
Correct |
66 ms |
20728 KB |
Output is correct |
5 |
Correct |
67 ms |
22008 KB |
Output is correct |
6 |
Correct |
51 ms |
20324 KB |
Output is correct |
7 |
Correct |
62 ms |
21628 KB |
Output is correct |
8 |
Correct |
70 ms |
22136 KB |
Output is correct |
9 |
Correct |
57 ms |
20344 KB |
Output is correct |
10 |
Correct |
70 ms |
22136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
22 ms |
10872 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
640 KB |
Output is correct |
10 |
Correct |
2 ms |
640 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
2 ms |
512 KB |
Output is correct |
13 |
Correct |
2 ms |
508 KB |
Output is correct |
14 |
Correct |
2 ms |
640 KB |
Output is correct |
15 |
Correct |
2 ms |
640 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
512 KB |
Output is correct |
18 |
Correct |
2 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
640 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
512 KB |
Output is correct |
22 |
Correct |
2 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
640 KB |
Output is correct |
24 |
Correct |
71 ms |
22136 KB |
Output is correct |
25 |
Correct |
71 ms |
22020 KB |
Output is correct |
26 |
Correct |
70 ms |
22264 KB |
Output is correct |
27 |
Correct |
66 ms |
20728 KB |
Output is correct |
28 |
Correct |
67 ms |
22008 KB |
Output is correct |
29 |
Correct |
51 ms |
20324 KB |
Output is correct |
30 |
Correct |
62 ms |
21628 KB |
Output is correct |
31 |
Correct |
70 ms |
22136 KB |
Output is correct |
32 |
Correct |
57 ms |
20344 KB |
Output is correct |
33 |
Correct |
70 ms |
22136 KB |
Output is correct |
34 |
Correct |
64 ms |
21496 KB |
Output is correct |
35 |
Correct |
50 ms |
19448 KB |
Output is correct |
36 |
Correct |
57 ms |
20600 KB |
Output is correct |
37 |
Correct |
3 ms |
512 KB |
Output is correct |
38 |
Correct |
45 ms |
19064 KB |
Output is correct |
39 |
Correct |
40 ms |
18424 KB |
Output is correct |
40 |
Correct |
44 ms |
19192 KB |
Output is correct |
41 |
Correct |
61 ms |
21496 KB |
Output is correct |
42 |
Correct |
64 ms |
21752 KB |
Output is correct |
43 |
Correct |
60 ms |
20600 KB |
Output is correct |
44 |
Correct |
42 ms |
18552 KB |
Output is correct |
45 |
Correct |
54 ms |
20088 KB |
Output is correct |
46 |
Correct |
53 ms |
19704 KB |
Output is correct |
47 |
Correct |
53 ms |
19960 KB |
Output is correct |
48 |
Correct |
56 ms |
20088 KB |
Output is correct |
49 |
Correct |
48 ms |
18792 KB |
Output is correct |
50 |
Correct |
58 ms |
20856 KB |
Output is correct |
51 |
Correct |
59 ms |
20472 KB |
Output is correct |
52 |
Correct |
61 ms |
21368 KB |
Output is correct |
53 |
Correct |
51 ms |
20472 KB |
Output is correct |
54 |
Correct |
59 ms |
21624 KB |
Output is correct |
55 |
Correct |
63 ms |
21624 KB |
Output is correct |
56 |
Correct |
57 ms |
21340 KB |
Output is correct |
57 |
Correct |
54 ms |
20856 KB |
Output is correct |
58 |
Correct |
68 ms |
21952 KB |
Output is correct |