답안 #117807

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
117807 2019-06-17T08:08:49 Z ainta Ljetopica (COI19_ljetopica) C++17
0 / 100
3 ms 384 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() {
  	freopen("input.txt","r",stdin);
	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:37:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    freopen("input.txt","r",stdin);
    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
ljetopica.cpp:39: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:40: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 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -