Submission #117664

# Submission time Handle Problem Language Result Execution time Memory
117664 2019-06-17T05:09:59 Z 윤지학(#2883) Ljetopica (COI19_ljetopica) C++14
100 / 100
37 ms 512 KB
#include <cstdio>
#include <algorithm>

using namespace std;

const int P = 1000000007;

int n, m;
char a[1001], b[1001], c[1001];
struct val {
	int x, y;
} d[2][1001];

void add(int &x, int y) {
	x += y;
	if (x >= P) x -= P;
}

int f(char *x, int f) {
	val *p = d[0], *q = d[1];
	int i, j, k, t, r;
	x++;
	for (k = 0; k <= m; k++) p[k] = { 0, 0 };
	for (i = j = 0, t = 1; i < n - 1; i++) {
		for (k = 0; k <= m; k++) q[k] = { 0, 0 };
		for (k = 0; k <= m; k++) {
			if (a[i] == 'L') {
				add(q[k + (k & 1)].x, (p[k].x << 1) % P);
				add(q[k + (k & 1)].y, p[k].y);
				add(q[k + !(k & 1)].x, ((p[k].x << 1) % P + p[k].y) % P);
				add(q[k + !(k & 1)].y, p[k].y);
			}
			else {
				add(q[k + !(k & 1)].x, (p[k].x << 1) % P);
				add(q[k + !(k & 1)].y, p[k].y);
				add(q[k + (k & 1)].x, ((p[k].x << 1) % P + p[k].y) % P);
				add(q[k + (k & 1)].y, p[k].y);
			}
		}
		if (x[i] == '1') {
			if (a[i] == 'L') {
				add(q[j + (j & 1)].x, (t << 1) % P);
				add(q[j + (j & 1)].y, 1);
			}
			else {
				add(q[j + !(j & 1)].x, (t << 1) % P);
				add(q[j + !(j & 1)].y, 1);
			}
		}
		if ((a[i] == 'L') ^ (x[i] == '0') ^ (j & 1)) j++;
		t = (t << 1 | (x[i] == '1')) % P;
		swap(p, q);
	}
	r = (p[m].x + t * f * (j == m)) % P;
	for (k = 0; k <= m; k++) p[k] = { 0, 0 };
	for (i = j = 0, t = 1; i < n - 1; i++) {
		for (k = 0; k <= m; k++) q[k] = { 0, 0 };
		for (k = 0; k <= m; k++) {
			if (a[i] == 'R') {
				add(q[k + (k & 1)].x, (p[k].x << 1) % P);
				add(q[k + (k & 1)].y, p[k].y);
				add(q[k + !(k & 1)].x, ((p[k].x << 1) % P + p[k].y) % P);
				add(q[k + !(k & 1)].y, p[k].y);
			}
			else {
				add(q[k + !(k & 1)].x, (p[k].x << 1) % P);
				add(q[k + !(k & 1)].y, p[k].y);
				add(q[k + (k & 1)].x, ((p[k].x << 1) % P + p[k].y) % P);
				add(q[k + (k & 1)].y, p[k].y);
			}
		}
		if (x[i] == '1') {
			if (a[i] == 'R') {
				add(q[j + (j & 1)].x, (t << 1) % P);
				add(q[j + (j & 1)].y, 1);
			}
			else {
				add(q[j + !(j & 1)].x, (t << 1) % P);
				add(q[j + !(j & 1)].y, 1);
			}
		}
		if ((a[i] == 'R') ^ (x[i] == '0') ^ (j & 1)) j++;
		t = (t << 1 | (x[i] == '1')) % P;
		swap(p, q);
	}
	return (r + (p[m].x + t * f * (j == m)) % P) % P;
}

int main() {
	int i, j, r;
	scanf("%d%d%s%s%s", &n, &m, a, b, c);
	printf("%d\n", (f(c, 1) - f(b, 0) + P) % P);
}

Compilation message

ljetopica.cpp: In function 'int main()':
ljetopica.cpp:90:6: warning: unused variable 'i' [-Wunused-variable]
  int i, j, r;
      ^
ljetopica.cpp:90:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j, r;
         ^
ljetopica.cpp:90:12: warning: unused variable 'r' [-Wunused-variable]
  int i, j, r;
            ^
ljetopica.cpp:91:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%s%s%s", &n, &m, a, b, c);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 384 KB Output is correct
2 Correct 15 ms 364 KB Output is correct
3 Correct 17 ms 256 KB Output is correct
4 Correct 34 ms 384 KB Output is correct
5 Correct 15 ms 256 KB Output is correct
6 Correct 37 ms 384 KB Output is correct
7 Correct 10 ms 384 KB Output is correct
8 Correct 17 ms 384 KB Output is correct
9 Correct 3 ms 256 KB Output is correct
10 Correct 17 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 2 ms 256 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 22 ms 384 KB Output is correct
25 Correct 15 ms 364 KB Output is correct
26 Correct 17 ms 256 KB Output is correct
27 Correct 34 ms 384 KB Output is correct
28 Correct 15 ms 256 KB Output is correct
29 Correct 37 ms 384 KB Output is correct
30 Correct 10 ms 384 KB Output is correct
31 Correct 17 ms 384 KB Output is correct
32 Correct 3 ms 256 KB Output is correct
33 Correct 17 ms 340 KB Output is correct
34 Correct 26 ms 256 KB Output is correct
35 Correct 11 ms 384 KB Output is correct
36 Correct 17 ms 384 KB Output is correct
37 Correct 34 ms 384 KB Output is correct
38 Correct 6 ms 256 KB Output is correct
39 Correct 30 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 21 ms 512 KB Output is correct
42 Correct 25 ms 384 KB Output is correct
43 Correct 26 ms 356 KB Output is correct
44 Correct 29 ms 256 KB Output is correct
45 Correct 10 ms 256 KB Output is correct
46 Correct 24 ms 256 KB Output is correct
47 Correct 26 ms 384 KB Output is correct
48 Correct 15 ms 256 KB Output is correct
49 Correct 3 ms 384 KB Output is correct
50 Correct 28 ms 384 KB Output is correct
51 Correct 16 ms 256 KB Output is correct
52 Correct 15 ms 384 KB Output is correct
53 Correct 35 ms 384 KB Output is correct
54 Correct 10 ms 256 KB Output is correct
55 Correct 28 ms 256 KB Output is correct
56 Correct 31 ms 384 KB Output is correct
57 Correct 5 ms 256 KB Output is correct
58 Correct 25 ms 256 KB Output is correct