#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
string a, b, c, x;
vector<string>strings;
set<string>st;
ll n, q;
struct crossing
{
int dd, ht, mid;
char toProp;
bool faltaprop;
bool allJ, allO, allI, iscorrect;
crossing *L, *R;
crossing(){}
crossing(int l, int r){
dd = l, ht = r;
mid = (dd+ht)/2;
if(l!=r){
L = new crossing(l, mid);
R = new crossing(mid+1, r);
allJ = L->allJ && R->allJ;
allO = L->allO && R->allO;
allI = L->allI && R->allI;
iscorrect = L->iscorrect && R->iscorrect;
}else{
allJ = a[dd] == 'J';
allO = a[dd] == 'O';
allI = a[dd] == 'I';
if(a[dd]==x[dd])iscorrect = true;
}
}
void propagate(){
if(!faltaprop)return;
L->insert(dd, mid, toProp);
R->insert(mid+1, ht, toProp);
iscorrect = L->iscorrect && R->iscorrect;
faltaprop=false;
}
void insert(int l, int r, char cual){
// cout << dd << " " << ht << " " << l << " " << r << endl;
if(dd == l && r==ht ){
if(cual == 'J' && allJ)iscorrect = true;
else if(cual == 'O'&&allO)iscorrect=true;
else if(cual == 'I' && allI)iscorrect = true;
else iscorrect=false;
//no hace falta propagar lo que hay aca
toProp = cual;
faltaprop = true;
return ;
}
propagate();
if(r<=mid)L->insert(l, r, cual);
else if(mid<l)R->insert(l, r, cual);
else {
L->insert(l, mid, cual);
R->insert(mid+1, r, cual);
}
iscorrect = L->iscorrect && R->iscorrect;
}
};
bool join(int a, int b){
string nueva="";
//cout << a << " " << b << endl;
for(int i = 0 ; i < n ; i++){
if(strings[a][i]==strings[b][i]){
nueva+=strings[a][i];
}else {
if((strings[a][i]=='J' && strings[b][i]=='O' )|| (strings[b][i]=='J' && strings[a][i]=='O'))nueva+="I";
else if((strings[a][i]=='I' && strings[b][i]=='O') || (strings[b][i]=='I' && strings[a][i]=='O'))nueva+="J";
else if((strings[a][i]=='I' && strings[b][i]=='J') || (strings[b][i]=='I' && strings[a][i]=='J'))nueva+="O";
}
}
if(st.find(nueva)==st.end()){
//cout << nueva << endl;
st.insert(nueva);
strings.pb(nueva);
}else{
return false;
}
return true;
}
void calculateString(){
bool ans = true;
while(ans){
ans = false;
int gen = strings.size();
for(int i = 0 ; i < gen-1; i++){
for(int j = i+1 ; j < gen ; j++){
if(join(i, j))ans = true;
}
}
}
}
void querys(){
cin>>q;
cin>>x;
if(st.find(x)!=st.end())cout<<"Yes\n";
else cout << "No\n";
int l, r;
char c;
for(int i = 0 ;i < q ; i++){
cin>>l>>r>>c;
for(int i = l-1 ; i <= r-1 ; i++){
x[i]=c;
}
//cout << "ask "<<x<<endl;
if(st.find(x)!=st.end())cout<<"Yes\n";
else cout << "No\n";
}
}
crossing *seg;
bool askforX(){
seg = new crossing(0, n-1);
return seg->iscorrect;
}
void input(){
//cin.tie(0);
//cout.tie(0);
//ios_base::sync_with_stdio(false);
cin>>n;
cin>>a>>b>>c;
strings.pb(a);
strings.pb(b);
strings.pb(c);
st.insert(a);
st.insert(b);
st.insert(c);
if(st.size()>=2){
calculateString();
querys();
}else{
cin>>q;
cin>>x;
if(askforX())cout << "Yes" << endl;
else cout << "No" << endl;
ll l, r;
char value;
for(int i = 0 ; i < q ; i++){
cin>>l>>r>>value;
seg->insert(l-1, r-1, value);
if(seg->iscorrect)cout<<"Yes" << endl;
else cout << "No" << endl;
}
}
}
int main(){
input();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
2160 KB |
Output is correct |
2 |
Correct |
355 ms |
2256 KB |
Output is correct |
3 |
Correct |
340 ms |
2200 KB |
Output is correct |
4 |
Correct |
371 ms |
2316 KB |
Output is correct |
5 |
Correct |
339 ms |
2220 KB |
Output is correct |
6 |
Correct |
331 ms |
2248 KB |
Output is correct |
7 |
Correct |
328 ms |
2292 KB |
Output is correct |
8 |
Correct |
346 ms |
2232 KB |
Output is correct |
9 |
Correct |
341 ms |
2288 KB |
Output is correct |
10 |
Correct |
352 ms |
2264 KB |
Output is correct |
11 |
Correct |
336 ms |
2220 KB |
Output is correct |
12 |
Correct |
345 ms |
2212 KB |
Output is correct |
13 |
Correct |
354 ms |
2276 KB |
Output is correct |
14 |
Correct |
348 ms |
2264 KB |
Output is correct |
15 |
Correct |
345 ms |
2240 KB |
Output is correct |
16 |
Correct |
351 ms |
2248 KB |
Output is correct |
17 |
Correct |
339 ms |
2176 KB |
Output is correct |
18 |
Correct |
356 ms |
2244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
2160 KB |
Output is correct |
2 |
Correct |
355 ms |
2256 KB |
Output is correct |
3 |
Correct |
340 ms |
2200 KB |
Output is correct |
4 |
Correct |
371 ms |
2316 KB |
Output is correct |
5 |
Correct |
339 ms |
2220 KB |
Output is correct |
6 |
Correct |
331 ms |
2248 KB |
Output is correct |
7 |
Correct |
328 ms |
2292 KB |
Output is correct |
8 |
Correct |
346 ms |
2232 KB |
Output is correct |
9 |
Correct |
341 ms |
2288 KB |
Output is correct |
10 |
Correct |
352 ms |
2264 KB |
Output is correct |
11 |
Correct |
336 ms |
2220 KB |
Output is correct |
12 |
Correct |
345 ms |
2212 KB |
Output is correct |
13 |
Correct |
354 ms |
2276 KB |
Output is correct |
14 |
Correct |
348 ms |
2264 KB |
Output is correct |
15 |
Correct |
345 ms |
2240 KB |
Output is correct |
16 |
Correct |
351 ms |
2248 KB |
Output is correct |
17 |
Correct |
339 ms |
2176 KB |
Output is correct |
18 |
Correct |
356 ms |
2244 KB |
Output is correct |
19 |
Correct |
656 ms |
23428 KB |
Output is correct |
20 |
Correct |
552 ms |
22500 KB |
Output is correct |
21 |
Correct |
540 ms |
21260 KB |
Output is correct |
22 |
Correct |
517 ms |
19224 KB |
Output is correct |
23 |
Correct |
394 ms |
3164 KB |
Output is correct |
24 |
Correct |
406 ms |
3168 KB |
Output is correct |
25 |
Correct |
558 ms |
22536 KB |
Output is correct |
26 |
Correct |
602 ms |
22416 KB |
Output is correct |
27 |
Correct |
565 ms |
22552 KB |
Output is correct |
28 |
Correct |
595 ms |
22488 KB |
Output is correct |
29 |
Correct |
543 ms |
21932 KB |
Output is correct |
30 |
Correct |
419 ms |
3220 KB |
Output is correct |
31 |
Correct |
553 ms |
22428 KB |
Output is correct |
32 |
Correct |
547 ms |
20672 KB |
Output is correct |
33 |
Correct |
417 ms |
3256 KB |
Output is correct |
34 |
Correct |
637 ms |
22528 KB |
Output is correct |
35 |
Correct |
566 ms |
17208 KB |
Output is correct |
36 |
Correct |
418 ms |
3148 KB |
Output is correct |
37 |
Correct |
396 ms |
3108 KB |
Output is correct |
38 |
Correct |
518 ms |
22480 KB |
Output is correct |
39 |
Correct |
447 ms |
22520 KB |
Output is correct |
40 |
Correct |
508 ms |
17584 KB |
Output is correct |
41 |
Correct |
622 ms |
25140 KB |
Output is correct |
42 |
Correct |
423 ms |
24336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
2160 KB |
Output is correct |
2 |
Correct |
355 ms |
2256 KB |
Output is correct |
3 |
Correct |
340 ms |
2200 KB |
Output is correct |
4 |
Correct |
371 ms |
2316 KB |
Output is correct |
5 |
Correct |
339 ms |
2220 KB |
Output is correct |
6 |
Correct |
331 ms |
2248 KB |
Output is correct |
7 |
Correct |
328 ms |
2292 KB |
Output is correct |
8 |
Correct |
346 ms |
2232 KB |
Output is correct |
9 |
Correct |
341 ms |
2288 KB |
Output is correct |
10 |
Correct |
352 ms |
2264 KB |
Output is correct |
11 |
Correct |
336 ms |
2220 KB |
Output is correct |
12 |
Correct |
345 ms |
2212 KB |
Output is correct |
13 |
Correct |
354 ms |
2276 KB |
Output is correct |
14 |
Correct |
348 ms |
2264 KB |
Output is correct |
15 |
Correct |
345 ms |
2240 KB |
Output is correct |
16 |
Correct |
351 ms |
2248 KB |
Output is correct |
17 |
Correct |
339 ms |
2176 KB |
Output is correct |
18 |
Correct |
356 ms |
2244 KB |
Output is correct |
19 |
Correct |
311 ms |
2244 KB |
Output is correct |
20 |
Correct |
385 ms |
2228 KB |
Output is correct |
21 |
Correct |
325 ms |
2252 KB |
Output is correct |
22 |
Correct |
315 ms |
2224 KB |
Output is correct |
23 |
Correct |
353 ms |
2184 KB |
Output is correct |
24 |
Correct |
323 ms |
2332 KB |
Output is correct |
25 |
Correct |
348 ms |
2292 KB |
Output is correct |
26 |
Correct |
317 ms |
2180 KB |
Output is correct |
27 |
Correct |
329 ms |
2212 KB |
Output is correct |
28 |
Correct |
295 ms |
2124 KB |
Output is correct |
29 |
Correct |
332 ms |
2192 KB |
Output is correct |
30 |
Correct |
297 ms |
2144 KB |
Output is correct |
31 |
Correct |
374 ms |
2308 KB |
Output is correct |
32 |
Correct |
318 ms |
2184 KB |
Output is correct |
33 |
Correct |
334 ms |
2352 KB |
Output is correct |
34 |
Correct |
302 ms |
2212 KB |
Output is correct |
35 |
Correct |
360 ms |
2180 KB |
Output is correct |
36 |
Correct |
323 ms |
2248 KB |
Output is correct |
37 |
Correct |
335 ms |
2272 KB |
Output is correct |
38 |
Correct |
318 ms |
2200 KB |
Output is correct |
39 |
Correct |
331 ms |
2244 KB |
Output is correct |
40 |
Correct |
373 ms |
2224 KB |
Output is correct |
41 |
Correct |
319 ms |
2280 KB |
Output is correct |
42 |
Correct |
330 ms |
2236 KB |
Output is correct |
43 |
Correct |
312 ms |
2220 KB |
Output is correct |
44 |
Correct |
328 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
326 ms |
2160 KB |
Output is correct |
2 |
Correct |
355 ms |
2256 KB |
Output is correct |
3 |
Correct |
340 ms |
2200 KB |
Output is correct |
4 |
Correct |
371 ms |
2316 KB |
Output is correct |
5 |
Correct |
339 ms |
2220 KB |
Output is correct |
6 |
Correct |
331 ms |
2248 KB |
Output is correct |
7 |
Correct |
328 ms |
2292 KB |
Output is correct |
8 |
Correct |
346 ms |
2232 KB |
Output is correct |
9 |
Correct |
341 ms |
2288 KB |
Output is correct |
10 |
Correct |
352 ms |
2264 KB |
Output is correct |
11 |
Correct |
336 ms |
2220 KB |
Output is correct |
12 |
Correct |
345 ms |
2212 KB |
Output is correct |
13 |
Correct |
354 ms |
2276 KB |
Output is correct |
14 |
Correct |
348 ms |
2264 KB |
Output is correct |
15 |
Correct |
345 ms |
2240 KB |
Output is correct |
16 |
Correct |
351 ms |
2248 KB |
Output is correct |
17 |
Correct |
339 ms |
2176 KB |
Output is correct |
18 |
Correct |
356 ms |
2244 KB |
Output is correct |
19 |
Correct |
656 ms |
23428 KB |
Output is correct |
20 |
Correct |
552 ms |
22500 KB |
Output is correct |
21 |
Correct |
540 ms |
21260 KB |
Output is correct |
22 |
Correct |
517 ms |
19224 KB |
Output is correct |
23 |
Correct |
394 ms |
3164 KB |
Output is correct |
24 |
Correct |
406 ms |
3168 KB |
Output is correct |
25 |
Correct |
558 ms |
22536 KB |
Output is correct |
26 |
Correct |
602 ms |
22416 KB |
Output is correct |
27 |
Correct |
565 ms |
22552 KB |
Output is correct |
28 |
Correct |
595 ms |
22488 KB |
Output is correct |
29 |
Correct |
543 ms |
21932 KB |
Output is correct |
30 |
Correct |
419 ms |
3220 KB |
Output is correct |
31 |
Correct |
553 ms |
22428 KB |
Output is correct |
32 |
Correct |
547 ms |
20672 KB |
Output is correct |
33 |
Correct |
417 ms |
3256 KB |
Output is correct |
34 |
Correct |
637 ms |
22528 KB |
Output is correct |
35 |
Correct |
566 ms |
17208 KB |
Output is correct |
36 |
Correct |
418 ms |
3148 KB |
Output is correct |
37 |
Correct |
396 ms |
3108 KB |
Output is correct |
38 |
Correct |
518 ms |
22480 KB |
Output is correct |
39 |
Correct |
447 ms |
22520 KB |
Output is correct |
40 |
Correct |
508 ms |
17584 KB |
Output is correct |
41 |
Correct |
622 ms |
25140 KB |
Output is correct |
42 |
Correct |
423 ms |
24336 KB |
Output is correct |
43 |
Correct |
311 ms |
2244 KB |
Output is correct |
44 |
Correct |
385 ms |
2228 KB |
Output is correct |
45 |
Correct |
325 ms |
2252 KB |
Output is correct |
46 |
Correct |
315 ms |
2224 KB |
Output is correct |
47 |
Correct |
353 ms |
2184 KB |
Output is correct |
48 |
Correct |
323 ms |
2332 KB |
Output is correct |
49 |
Correct |
348 ms |
2292 KB |
Output is correct |
50 |
Correct |
317 ms |
2180 KB |
Output is correct |
51 |
Correct |
329 ms |
2212 KB |
Output is correct |
52 |
Correct |
295 ms |
2124 KB |
Output is correct |
53 |
Correct |
332 ms |
2192 KB |
Output is correct |
54 |
Correct |
297 ms |
2144 KB |
Output is correct |
55 |
Correct |
374 ms |
2308 KB |
Output is correct |
56 |
Correct |
318 ms |
2184 KB |
Output is correct |
57 |
Correct |
334 ms |
2352 KB |
Output is correct |
58 |
Correct |
302 ms |
2212 KB |
Output is correct |
59 |
Correct |
360 ms |
2180 KB |
Output is correct |
60 |
Correct |
323 ms |
2248 KB |
Output is correct |
61 |
Correct |
335 ms |
2272 KB |
Output is correct |
62 |
Correct |
318 ms |
2200 KB |
Output is correct |
63 |
Correct |
331 ms |
2244 KB |
Output is correct |
64 |
Correct |
373 ms |
2224 KB |
Output is correct |
65 |
Correct |
319 ms |
2280 KB |
Output is correct |
66 |
Correct |
330 ms |
2236 KB |
Output is correct |
67 |
Correct |
312 ms |
2220 KB |
Output is correct |
68 |
Correct |
328 ms |
2384 KB |
Output is correct |
69 |
Execution timed out |
7095 ms |
8056 KB |
Time limit exceeded |
70 |
Halted |
0 ms |
0 KB |
- |