답안 #117809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117809 2019-06-17T08:09:21 Z ainta Ljetopica (COI19_ljetopica) C++17
100 / 100
220 ms 24184 KB
#include<cstdio>
#include<algorithm>
using namespace std;
int n, K, chk[1010], C[1010][1010][2];
long long S[1010][1010][2], Mod = 1000000007;
char p[1010], B[1010], E[1010];
int Get(char *T) {
	int i, j, k, l, c = 0;
	for (i = 0; i <= n; i++)for (j = 0; j <= n; j++)S[i][j][0] = S[i][j][1] = 0, C[i][j][0] = C[i][j][1] = 0;
	long long s = 1;
	for (i = 0; i < n; i++) {
		if (T[i] == '1') {
			int t = c;
			if (i && (T[i - 1] == '1') != (chk[i] == 1))t++;
			C[i + 1][t][0] = (C[i + 1][t][0] + 1)%Mod;
			S[i + 1][t][0] = (S[i + 1][t][0] + s * 2 % Mod) % Mod;
		}
		if (i)c += ((T[i] != T[i - 1]) != (chk[i] == 1));
		s = (s * 2 + T[i] - '0') % Mod;
		for (j = 0; j <= i; j++) {
			for (k = 0; k < 2; k++) {
				for (l = 0; l < 2; l++) {
					int ck = 0;
					if ((k != l) != (chk[i] == 1))ck = 1;
					C[i + 1][j+ck][k] = (C[i + 1][j+ck][k] + C[i][j][l]) % Mod;
					S[i + 1][j+ck][k] = (S[i + 1][j+ck][k] + S[i][j][l] * 2 + k * C[i][j][l]) % Mod;
				}
			}
		}
	}
	S[n][c][T[n - 1]-'0'] += s;
	long long res = S[n][K][0] + S[n][K][1];
	if (K)res += S[n][K - 1][0] + S[n][K - 1][1];
	return res % Mod;
}
int main() {
	int i, j;
	scanf("%d%d", &n, &K);
	scanf("%s%s%s", p,B,E);
	n--;
	for (i = 1; i < n; i++) {
		if (p[i] != p[i - 1])chk[i] = 1;
	}
	int res = Get(E+1);
	for (i = n; i >= 0; i--) {
		if (B[i] == '1')break;
	}
	if (i) {
		for (j = i + 1; j <= n; j++)B[j] = '1';
		B[i] = '0';
		res = (res+Mod-Get(B+1))%Mod;
	}
	printf("%d\n", res);
}

Compilation message

ljetopica.cpp: In function 'int main()':
ljetopica.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &K);
  ~~~~~^~~~~~~~~~~~~~~~
ljetopica.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s%s%s", p,B,E);
  ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 24184 KB Output is correct
2 Correct 130 ms 22904 KB Output is correct
3 Correct 104 ms 21632 KB Output is correct
4 Correct 95 ms 20516 KB Output is correct
5 Correct 85 ms 19456 KB Output is correct
6 Correct 108 ms 18040 KB Output is correct
7 Correct 68 ms 16352 KB Output is correct
8 Correct 59 ms 14720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 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 504 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 484 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 23976 KB Output is correct
2 Correct 126 ms 24080 KB Output is correct
3 Correct 123 ms 24160 KB Output is correct
4 Correct 123 ms 24080 KB Output is correct
5 Correct 125 ms 24072 KB Output is correct
6 Correct 122 ms 24076 KB Output is correct
7 Correct 128 ms 24088 KB Output is correct
8 Correct 127 ms 24080 KB Output is correct
9 Correct 125 ms 24076 KB Output is correct
10 Correct 128 ms 24064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 24184 KB Output is correct
2 Correct 130 ms 22904 KB Output is correct
3 Correct 104 ms 21632 KB Output is correct
4 Correct 95 ms 20516 KB Output is correct
5 Correct 85 ms 19456 KB Output is correct
6 Correct 108 ms 18040 KB Output is correct
7 Correct 68 ms 16352 KB Output is correct
8 Correct 59 ms 14720 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 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 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 504 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 484 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 128 ms 23976 KB Output is correct
25 Correct 126 ms 24080 KB Output is correct
26 Correct 123 ms 24160 KB Output is correct
27 Correct 123 ms 24080 KB Output is correct
28 Correct 125 ms 24072 KB Output is correct
29 Correct 122 ms 24076 KB Output is correct
30 Correct 128 ms 24088 KB Output is correct
31 Correct 127 ms 24080 KB Output is correct
32 Correct 125 ms 24076 KB Output is correct
33 Correct 128 ms 24064 KB Output is correct
34 Correct 125 ms 23808 KB Output is correct
35 Correct 110 ms 21856 KB Output is correct
36 Correct 119 ms 22656 KB Output is correct
37 Correct 220 ms 22912 KB Output is correct
38 Correct 107 ms 22180 KB Output is correct
39 Correct 103 ms 21920 KB Output is correct
40 Correct 109 ms 22244 KB Output is correct
41 Correct 119 ms 23440 KB Output is correct
42 Correct 122 ms 23936 KB Output is correct
43 Correct 113 ms 22896 KB Output is correct
44 Correct 105 ms 21824 KB Output is correct
45 Correct 113 ms 22400 KB Output is correct
46 Correct 108 ms 22068 KB Output is correct
47 Correct 109 ms 22460 KB Output is correct
48 Correct 108 ms 22252 KB Output is correct
49 Correct 109 ms 22284 KB Output is correct
50 Correct 117 ms 23476 KB Output is correct
51 Correct 112 ms 22724 KB Output is correct
52 Correct 117 ms 23440 KB Output is correct
53 Correct 123 ms 24080 KB Output is correct
54 Correct 126 ms 24092 KB Output is correct
55 Correct 127 ms 24072 KB Output is correct
56 Correct 122 ms 24072 KB Output is correct
57 Correct 123 ms 24080 KB Output is correct
58 Correct 124 ms 24080 KB Output is correct