#include <bits/stdc++.h>
namespace MX {
constexpr int A = 26;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
// consider string as a number in modulo 26
//
// call string a, b the 2 strings you need to check if close (after the op)
// clarification in first example (abc is string a, ced is string b)
//
// doing op (adding 11 to the pair) on string b is equivalent to subtracting
// string a, so we can keep string b constant
//
// we know how much to add on each position, consider an array that
// represents value needed to add to char in string a to get b start with 0,
// and construct bi - ai via the +1 on consec operation (and its reverse as
// mentioned above) for which array is it possible to build such an array so
// when added to ai you get bi
//
// lets call this array above c, ci = bi - ai for all i
//
// check selected problems: https://oj.uz/problem/view/COI23_bliskost for
// diagram
//
// so basically first operation is c_0, c_1 - c_0, c2 - c1 + c0 ... c_n-2 -
// c_n-3 + ... +/- c0 should be equal to c_(n - 1) ofc in modulo 26
//
// c_(n - 1) + c_(n - 3) + ... = c_(n - 2) + c_(n - 4) + ...
//
// so odd positions sum should be equal to even positions sum (ofc in mod
// 26) whcih we can keep track trivially
int N, Q;
std::cin >> N >> Q;
std::string A;
std::cin >> A;
std::string B;
std::cin >> B;
int odd = 0, eve = 0;
for (int i = 0; i < N; i++) {
(i % 2 ? odd : eve) += (B[i] - A[i] + MX::A) % MX::A;
odd += MX::A;
odd %= MX::A;
eve += MX::A;
eve %= MX::A;
}
std::cout << (odd == eve ? "da" : "ne") << "\n";
for (int q = 0; q < Q; q++) {
int p;
char c;
std::cin >> p >> c;
p--;
(p % 2 ? odd : eve) -= (B[p] - A[p]);
A[p] = c;
(p % 2 ? odd : eve) += (B[p] - A[p]);
odd += MX::A;
odd %= MX::A;
eve += MX::A;
eve %= MX::A;
std::cout << (odd == eve ? "da" : "ne") << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
508 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
508 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
9 ms |
4536 KB |
Output is correct |
32 |
Correct |
9 ms |
4392 KB |
Output is correct |
33 |
Correct |
8 ms |
4408 KB |
Output is correct |
34 |
Correct |
8 ms |
4504 KB |
Output is correct |
35 |
Correct |
7 ms |
4600 KB |
Output is correct |
36 |
Correct |
7 ms |
4848 KB |
Output is correct |
37 |
Correct |
9 ms |
4852 KB |
Output is correct |
38 |
Correct |
7 ms |
4504 KB |
Output is correct |
39 |
Correct |
7 ms |
4848 KB |
Output is correct |
40 |
Correct |
8 ms |
4844 KB |
Output is correct |
41 |
Correct |
8 ms |
4404 KB |
Output is correct |
42 |
Correct |
8 ms |
4520 KB |
Output is correct |
43 |
Correct |
8 ms |
4856 KB |
Output is correct |
44 |
Correct |
7 ms |
4520 KB |
Output is correct |
45 |
Correct |
10 ms |
4504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
12 ms |
1112 KB |
Output is correct |
17 |
Correct |
16 ms |
1112 KB |
Output is correct |
18 |
Correct |
16 ms |
1116 KB |
Output is correct |
19 |
Correct |
11 ms |
1112 KB |
Output is correct |
20 |
Correct |
13 ms |
1072 KB |
Output is correct |
21 |
Correct |
11 ms |
1112 KB |
Output is correct |
22 |
Correct |
11 ms |
988 KB |
Output is correct |
23 |
Correct |
10 ms |
1116 KB |
Output is correct |
24 |
Correct |
12 ms |
1004 KB |
Output is correct |
25 |
Correct |
11 ms |
984 KB |
Output is correct |
26 |
Correct |
11 ms |
1116 KB |
Output is correct |
27 |
Correct |
13 ms |
1136 KB |
Output is correct |
28 |
Correct |
13 ms |
1092 KB |
Output is correct |
29 |
Correct |
11 ms |
888 KB |
Output is correct |
30 |
Correct |
11 ms |
1092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
508 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
12 ms |
1112 KB |
Output is correct |
32 |
Correct |
16 ms |
1112 KB |
Output is correct |
33 |
Correct |
16 ms |
1116 KB |
Output is correct |
34 |
Correct |
11 ms |
1112 KB |
Output is correct |
35 |
Correct |
13 ms |
1072 KB |
Output is correct |
36 |
Correct |
11 ms |
1112 KB |
Output is correct |
37 |
Correct |
11 ms |
988 KB |
Output is correct |
38 |
Correct |
10 ms |
1116 KB |
Output is correct |
39 |
Correct |
12 ms |
1004 KB |
Output is correct |
40 |
Correct |
11 ms |
984 KB |
Output is correct |
41 |
Correct |
11 ms |
1116 KB |
Output is correct |
42 |
Correct |
13 ms |
1136 KB |
Output is correct |
43 |
Correct |
13 ms |
1092 KB |
Output is correct |
44 |
Correct |
11 ms |
888 KB |
Output is correct |
45 |
Correct |
11 ms |
1092 KB |
Output is correct |
46 |
Correct |
13 ms |
1188 KB |
Output is correct |
47 |
Correct |
11 ms |
1116 KB |
Output is correct |
48 |
Correct |
11 ms |
1136 KB |
Output is correct |
49 |
Correct |
12 ms |
1224 KB |
Output is correct |
50 |
Correct |
11 ms |
1140 KB |
Output is correct |
51 |
Correct |
12 ms |
1116 KB |
Output is correct |
52 |
Correct |
12 ms |
1344 KB |
Output is correct |
53 |
Correct |
15 ms |
1116 KB |
Output is correct |
54 |
Correct |
14 ms |
1116 KB |
Output is correct |
55 |
Correct |
11 ms |
1112 KB |
Output is correct |
56 |
Correct |
13 ms |
1376 KB |
Output is correct |
57 |
Correct |
14 ms |
1116 KB |
Output is correct |
58 |
Correct |
12 ms |
1344 KB |
Output is correct |
59 |
Correct |
11 ms |
1140 KB |
Output is correct |
60 |
Correct |
13 ms |
1116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
508 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
9 ms |
4536 KB |
Output is correct |
32 |
Correct |
9 ms |
4392 KB |
Output is correct |
33 |
Correct |
8 ms |
4408 KB |
Output is correct |
34 |
Correct |
8 ms |
4504 KB |
Output is correct |
35 |
Correct |
7 ms |
4600 KB |
Output is correct |
36 |
Correct |
7 ms |
4848 KB |
Output is correct |
37 |
Correct |
9 ms |
4852 KB |
Output is correct |
38 |
Correct |
7 ms |
4504 KB |
Output is correct |
39 |
Correct |
7 ms |
4848 KB |
Output is correct |
40 |
Correct |
8 ms |
4844 KB |
Output is correct |
41 |
Correct |
8 ms |
4404 KB |
Output is correct |
42 |
Correct |
8 ms |
4520 KB |
Output is correct |
43 |
Correct |
8 ms |
4856 KB |
Output is correct |
44 |
Correct |
7 ms |
4520 KB |
Output is correct |
45 |
Correct |
10 ms |
4504 KB |
Output is correct |
46 |
Correct |
12 ms |
1112 KB |
Output is correct |
47 |
Correct |
16 ms |
1112 KB |
Output is correct |
48 |
Correct |
16 ms |
1116 KB |
Output is correct |
49 |
Correct |
11 ms |
1112 KB |
Output is correct |
50 |
Correct |
13 ms |
1072 KB |
Output is correct |
51 |
Correct |
11 ms |
1112 KB |
Output is correct |
52 |
Correct |
11 ms |
988 KB |
Output is correct |
53 |
Correct |
10 ms |
1116 KB |
Output is correct |
54 |
Correct |
12 ms |
1004 KB |
Output is correct |
55 |
Correct |
11 ms |
984 KB |
Output is correct |
56 |
Correct |
11 ms |
1116 KB |
Output is correct |
57 |
Correct |
13 ms |
1136 KB |
Output is correct |
58 |
Correct |
13 ms |
1092 KB |
Output is correct |
59 |
Correct |
11 ms |
888 KB |
Output is correct |
60 |
Correct |
11 ms |
1092 KB |
Output is correct |
61 |
Correct |
13 ms |
1188 KB |
Output is correct |
62 |
Correct |
11 ms |
1116 KB |
Output is correct |
63 |
Correct |
11 ms |
1136 KB |
Output is correct |
64 |
Correct |
12 ms |
1224 KB |
Output is correct |
65 |
Correct |
11 ms |
1140 KB |
Output is correct |
66 |
Correct |
12 ms |
1116 KB |
Output is correct |
67 |
Correct |
12 ms |
1344 KB |
Output is correct |
68 |
Correct |
15 ms |
1116 KB |
Output is correct |
69 |
Correct |
14 ms |
1116 KB |
Output is correct |
70 |
Correct |
11 ms |
1112 KB |
Output is correct |
71 |
Correct |
13 ms |
1376 KB |
Output is correct |
72 |
Correct |
14 ms |
1116 KB |
Output is correct |
73 |
Correct |
12 ms |
1344 KB |
Output is correct |
74 |
Correct |
11 ms |
1140 KB |
Output is correct |
75 |
Correct |
13 ms |
1116 KB |
Output is correct |
76 |
Correct |
139 ms |
16140 KB |
Output is correct |
77 |
Correct |
136 ms |
16560 KB |
Output is correct |
78 |
Correct |
134 ms |
16040 KB |
Output is correct |
79 |
Correct |
137 ms |
16160 KB |
Output is correct |
80 |
Correct |
135 ms |
16004 KB |
Output is correct |
81 |
Correct |
144 ms |
16144 KB |
Output is correct |
82 |
Correct |
134 ms |
16000 KB |
Output is correct |
83 |
Correct |
135 ms |
15960 KB |
Output is correct |
84 |
Correct |
135 ms |
16004 KB |
Output is correct |
85 |
Correct |
157 ms |
16060 KB |
Output is correct |
86 |
Correct |
167 ms |
16452 KB |
Output is correct |
87 |
Correct |
145 ms |
16568 KB |
Output is correct |
88 |
Correct |
151 ms |
16560 KB |
Output is correct |
89 |
Correct |
142 ms |
16072 KB |
Output is correct |
90 |
Correct |
142 ms |
16460 KB |
Output is correct |