Submission #117921

# Submission time Handle Problem Language Result Execution time Memory
117921 2019-06-17T12:27:59 Z onjo0127 Ljetopica (COI19_ljetopica) C++11
17 / 100
104 ms 27776 KB
#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

int N;
long long C[1009][1009][2], D[1009][1009][2], bi[1009];
char S[1009], A[1009], B[1009], H = ('L' ^ 'R');

void go(int idx, int left, bool ok) {
	long long &CC = C[idx][left][ok], &DD = D[idx][left][ok];

	if(idx == N) {
		if(left == 0) CC = DD = 1;
		else CC = DD = 0;
		return;
	}
	if(DD != -1) return;

	char X = S[idx];
	if(!ok) X ^= H;

	go(idx+1, left, ok);
	if(left) go(idx+1, left-1, !ok);

	CC = C[idx+1][left][ok];
	if(left) CC += C[idx+1][left-1][!ok];
	CC %= MOD;

	if(X == 'L') {
		DD = D[idx+1][left][ok] + C[idx+1][left][ok] * bi[N - idx - 1] % MOD;
		DD %= MOD;
		if(left) DD += D[idx+1][left-1][!ok] + C[idx+1][left-1][!ok] * bi[N - idx] % MOD, DD %= MOD;
	}
	else {
		DD = D[idx+1][left][ok] + C[idx+1][left][ok] * bi[N - idx] % MOD;
		DD %= MOD;
		if(left) DD += D[idx+1][left-1][!ok] + C[idx+1][left-1][!ok] * bi[N - idx - 1] % MOD, DD %= MOD;
	}
}

int main() {
    int K; scanf("%d%d",&N,&K);
    bi[0] = 1; for(int i=1; i<=N; i++) bi[i] = bi[i-1] * 2 % MOD;
    scanf(" %s %s %s", S+1, A, B);
   	memset(D, -1, sizeof(D));
    go(1, K, 1); go(1, K, 0);
    printf("%lld", (D[1][K][0] + D[1][K][1]) % MOD);
    return 0; 
}

Compilation message

ljetopica.cpp: In function 'int main()':
ljetopica.cpp:43:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     int K; scanf("%d%d",&N,&K);
            ~~~~~^~~~~~~~~~~~~~
ljetopica.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %s %s %s", S+1, A, B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 20352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 16384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 26884 KB Output is correct
2 Correct 49 ms 25340 KB Output is correct
3 Correct 52 ms 25768 KB Output is correct
4 Correct 104 ms 27776 KB Output is correct
5 Correct 67 ms 25208 KB Output is correct
6 Correct 75 ms 27640 KB Output is correct
7 Correct 37 ms 23552 KB Output is correct
8 Correct 52 ms 25848 KB Output is correct
9 Correct 19 ms 20736 KB Output is correct
10 Correct 49 ms 25336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 20352 KB Output isn't correct
2 Halted 0 ms 0 KB -