QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#246735 | #5161. Last Guess | thanhchauns2# | WA | 3ms | 4912kb | C++20 | 4.4kb | 2023-11-11 02:46:26 | 2023-11-11 02:46:27 |
Judging History
answer
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define rd read()
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define p pair
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
namespace {
typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair<int,int> pii; typedef pair<ll,ll> pll;
// istream& operator>>(istream& i, ll &v){ long long t; i >> t; v = t; return i;}
// ostream& operator<<(ostream& out, ll &v){
// vector<long long> x; ll u = v;
// while(u){x.pb(u % 10); u /= 10;}
// reverse(x.begin(), x.end());
// for (auto &o : x){out << o;} return out;
// }
ll read(){ ll x; cin >> x; return x; } ld PI = 3.14159265358979323846; ld eps = 1e-6; ll mod = 1e9 + 7;
template<typename T> void Unique(T &a) {a.erase(unique(a.begin(), a.end()), a.end());}
template<typename T1, typename T2> ostream& operator<<(ostream& out, const p<T1, T2>& x) {return out << x.f << ' ' << x.s;}
template<typename T1, typename T2> istream& operator>>(istream& in, p<T1, T2>& x) {return in >> x.f >> x.s;}
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {for(auto &x : a) out << x << ' '; return out;};
template<typename T> istream& operator>>(istream& in, deque<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, deque<T>& a) {for(auto &x : a) out << x << ' '; return out;};
template<typename T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
template<typename T> using ordered_multiset = tree<T, null_type,less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
template<typename T> using pq = priority_queue<T>; template<typename T> using reverse_pq = priority_queue<T, vector<T>, greater<T> >;
template<typename T> using matrix = vector<vector<T> >; template<typename T> using rubik = vector<vector<vector<T> > >;
vector<ll> rdv(int sz) { vector<ll> x(sz); cin >> x;return x; }
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
const int N = 500 + 5;
} // main template
ll color[30]{}, l[30]{}, lx[30]{}, st[30]{}, got[N]{}, a = 0, b = 0;
void solve(){
ll n = rd - 1, m = rd; set<ll> save[26], ans[m];
string fi = ""; b = m;
for (int i = 0; i < m; i++){
color[i] = 5; fi += '?';
for (int j = 0; j < 26; j++){
save[j].insert(i);
ans[i].insert(j);
}
}
for (int _ = 0; _ < n; _++){
string s, t; cin >> s >> t;
for (int i = 0; i < m; i++){
if (t[i] == 'G'){ // GREEN
for (int j = 0; j < 26; j++){
if (j == s[i] - 'a'){
continue;
}
save[j].erase(i);
ans[i].erase(j);
}
fi[i] = s[i];
if (!got[i]){
b--;
}
got[i] = 1;
if (l[s[i] - 'a'] > 0){
lx[s[i] - 'a'] -= 1; a--;
}
} else if (t[i] == 'Y'){ // YELLOW
lx[s[i] - 'a']++; a++;
save[s[i] - 'a'].erase(i);
ans[i].erase(s[i] - 'a');
} else { // BLACK
st[s[i] - 'a'] = 1;
save[s[i] - 'a'].erase(i);
ans[i].erase(s[i] - 'a');
}
}
for (int i = 0; i < 26; i++){
l[i] = lx[i];
}
}
// cout << fi << '\n';
// cout << a << ' ' << b << '\n';
// for (int i = 0; i < 26; i++){
// cout << (char)(i + 'a') << ' ' << save[i].size() << '\n';
// }
while (true){
ll x;
for (int i = 0; i < 26; i++){
if ((ll)save[i].size() < 1){
continue;
}
if ((ll)save[i].size() == l[i]){
if (st[i] == 0 && a != b){
continue;
}
for (auto &x : save[i]){
fi[x] = (char)(i + 'a');
ans[x].erase(i);
}
save[i].clear(); l[i] = 0;
goto nxt;
}
}
for (int i = 0; i < m; i++){
if (fi[i] == '?'){
for (auto &x : ans[i]){
if (l[x] > 0){
fi[i] = (char)(x + 'a');
ans[i].erase(x);
save[x].erase(i);
l[x]--; goto nxt;
}
}
x = *ans[i].begin();
fi[i] = (char)(x + 'a');
ans[i].erase(x);
save[x].erase(i);
goto nxt;
}
}
break;
nxt:;
// cout << fi << '\n';
}
cout << fi << '\n';
}
signed main(){
cin.tie(0) -> ios::sync_with_stdio(false);
for (int i = 1, j = 1; i > 0; i--, j++) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3768kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabdcbeadaaa
result:
ok
Test #3:
score: -100
Wrong Answer
time: 3ms
memory: 4912kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
abcdefghijklmnoooprstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaoaaaaaaaa...
result:
FAIL Wrong answer: does not fit word 0