This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18;
vector<string> get_strings(string &xx, string &y, string &z){
string s[3] = {xx, y, z};
int n = int(s[0].length());
map<string, int> mp;
queue<string> q;
for(int l = 0; l < 3; ++l) mp[s[l]] = 1, q.emplace(s[l]);
char t[3] = {'J', 'O', 'I'};
//~ int cnt = 0;
vector<string> ret;
while(!q.empty()){
string x = q.front(); q.pop();
string tt = ""; tt.resize(n);
for(int l = 0; l < 3; ++l){
for(int i = 0; i < n; ++i) if(x[i] == s[l][i]) tt[i] = x[i];
else{
int a, b;
for(int j = 0; j < 3; ++j) if(t[j] == x[i]) a = j;
for(int j = 0; j < 3; ++j) if(t[j] == s[l][i]) b = j;
if(a && b) tt[i] = t[0];
else if(max(a, b) > 1) tt[i] = t[1];
else tt[i] = t[2];
}
if(mp[tt] != 1) mp[tt] = 1, q.emplace(tt); //, cout << ":\n" << x << "\n" << s[l] << "\n" << tt << "\n\n";
}
//~ cout << x << "\n";
ret.emplace_back(x);
}
return ret;
}
void answer(){
int n, q; scanf("%d", &n);
string s[3] = {"", "", ""}, t="";
char c;
for(int l = 0; l < 3; ++l){
c = getchar_unlocked();
for(int i = 0; i < n; ++i) c = getchar_unlocked(), s[l] += c;
}
scanf("%d\n", &q);
for(int i = 0; i < n; ++i) c = getchar_unlocked(), t += c;
vector<string> st = get_strings(s[0], s[1], s[2]);
bool good = 0;
for(string u : st){
if(t == u) good = 1;
}
printf(good ? "Yes\n" : "No\n");
for(int i = 0; i < q; ++i){
int a, b;
scanf("%d%d %c", &a, &b, &c);
for(int j = a-1; j < b; ++j) t[j] = c;
good = 0;
for(string &u : st) if(t == u) good = 1;
printf(good ? "Yes\n" : "No\n");
}
}
int main(){
int T = 1;
//~ ios_base::sync_with_stdio(0); cin.tie(0);
for(++T; --T; ) answer();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void answer()':
Main.cpp:41:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
41 | int n, q; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
Main.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d\n", &q);
| ~~~~~^~~~~~~~~~~~
Main.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
58 | scanf("%d%d %c", &a, &b, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |