QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106336 | #5161. Last Guess | joesmitty | WA | 3ms | 4428kb | C++14 | 6.1kb | 2023-05-17 14:22:22 | 2023-05-17 14:22:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef vector<int> vi;
typedef vector< vector <int> > vvi;
typedef pair<int, int> pii;
typedef pair < pair < int, int >, int > piii;
typedef pair < pair <int, int > , pair <int, int> > piiii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define RFOR(i,a,b) for(int i = a-1; i >= b; i --)
#define all(a) a.begin(), a.end()
//#define endl '\n';
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
template <typename T>
void pr(vector<T> &v) {
FOR(i, 0, sz(v)) cout << v[i] << " ";
cout << endl;
}
template <typename T>
void pr(vector<vector<T> > &v) {
FOR(i, 0, sz(v)) { pr(v[i]); }
}
template <typename T>
void re(T &x) {
cin >> x;
}
template <typename T>
void re(vector<T> &a) {
FOR(i, 0, sz(a)) re(a[i]);
}
template <class Arg, class... Args>
void re(Arg &first, Args &... rest) {
re(first);
re(rest...);
}
template <typename T>
void pr(T x) {
cout << x << endl;
}
template <class Arg, class... Args>
void pr(const Arg &first, const Args &... rest) {
cout << first << " ";
pr(rest...);
cout << endl;
}
void ps() { cout << endl; }
template<class T, class... Ts>
void ps(const T& t, const Ts&... ts) {
cout << t; if (sizeof...(ts)) cout << " "; ps(ts...);
}
const ll MOD = 998244353;
#define inf 1e18;
#define INF INT_MAX;
long double PI = 4*atan(1);
long double eps = 1e-12;
bool dfs(int a, int L, vector<vi>& g, vi& btoa, vi& A, vi& B) {
if (A[a] != L) return 0;
A[a] = -1;
for (int b : g[a]) if (B[b] == L + 1) {
B[b] = 0;
if (btoa[b] == -1 || dfs(btoa[b], L + 1, g, btoa, A, B)) {
return btoa[b] = a, 1;
}
}
return 0;
}
int hopcroftKarp(vector<vi>& g, vi& btoa) {
int res = 0;
vi A(g.size()), B(btoa.size()), cur, next;
for (;;) {
fill(all(A), 0);
fill(all(B), 0);
cur.clear();
for (int a : btoa) if(a != -1) A[a] = -1;
FOR(a,0,sz(g)) if(A[a] == 0) cur.push_back(a);
for (int lay = 1;; lay++) {
bool islast = 0;
next.clear();
for (int a : cur) for (int b : g[a]) {
if (btoa[b] == -1) {
B[b] = lay;
islast = 1;
}
else if (btoa[b] != a && !B[b]) {
B[b] = lay;
next.push_back(btoa[b]);
}
}
if (islast) break;
if (next.empty()) return res;
for (int a : next) A[a] = lay;
cur.swap(next);
}
FOR(a,0,sz(g)) res += dfs(a, 0, g, btoa, A, B);
}
}
vi upper(26, 1e9);
vi trueupper(26, 1e9);
vi lower(26, 0);
int green[26] = {};
int pos_to_orig[510] = {};
char idxtochar[510] = {};
int banned[510][26] = {};
vvi adj;
int main() {
//auto start = chrono::high_resolution_clock::now();
ios_base::sync_with_stdio(0);cin.tie(0);
// freopen("promote.in", "r", stdin);
// freopen("promote.out", "w", stdout);
#ifdef DEBUG
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int g,L; cin >> g >> L;
vector<string> guess(g-1), res(g-1);
FOR(i,0,g-1) {
cin >> guess[i] >> res[i];
}
string ans = "";
FOR(i,0,L) ans += '*';
FOR(i,0,g-1) {
int cnt[26][3] = {};
FOR(j,0,L) {
if(res[i][j] == 'G') {
cnt[guess[i][j]-'a'][2]++;
ans[j] = guess[i][j];
}
else if(res[i][j] == 'Y') {
cnt[guess[i][j]-'a'][1]++;
banned[j][guess[i][j] - 'a'] = 1;
} else {
cnt[guess[i][j]-'a'][0]++;
banned[j][guess[i][j] - 'a'] = 1;
}
}
FOR(j,0,26) {
lower[j] = max(lower[j], cnt[j][1] + cnt[j][2]);
if(cnt[j][0] > 0) {
upper[j] = min(upper[j], cnt[j][1] + cnt[j][2]);
}
trueupper[j] = min({trueupper[j], upper[j], L - cnt[j][1] - cnt[j][0]});
}
// cout << trueupper[1] << endl;
}
// cout << ans << endl;
int num_need_ans = 0;
FOR(i,0,L) {
if(ans[i] == '*') {
pos_to_orig[num_need_ans] = i;
num_need_ans++;
} else {
green[ans[i] - 'a']++;
}
}
int num_need_char = 0;
FOR(i,0,26) {
int rem = lower[i] - green[i];
if(upper[i] < 1e6) rem = upper[i] - green[i];
FOR(j,0,rem) {
idxtochar[num_need_char] = 'a' + i;
num_need_char++;
}
}
if(num_need_char < num_need_ans) {
FOR(i,0,26) {
if(upper[i] < 1e6 || trueupper[i] - green[i] == 0) continue;
int tot = trueupper[i] - green[i];
char newchar = 'a' + i;
while(num_need_char < num_need_ans && tot) {
idxtochar[num_need_char] = newchar;
num_need_char++;
tot--;
}
}
}
int nn = num_need_ans;
adj.resize(nn);
FOR(i,0,nn) {
int o_idx = pos_to_orig[i];
FOR(j,0,nn) {
char res = idxtochar[j];
if(banned[o_idx][res-'a'] == 0) {
adj[i].pb(j);
}
}
}
vi btoa(nn, -1);
int tot = hopcroftKarp(adj, btoa);
// assert(tot == nn);
FOR(i,0,nn) {
int idx = btoa[i];
ans[pos_to_orig[idx]] = idxtochar[i];
}
cout << ans << endl;
// auto stop = chrono::high_resolution_clock::now();
// auto duration = chrono::duration_cast<chrono::microseconds>(stop - start);
// cout << duration.count() << endl;
//cin.close();
//cout.close();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3432kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 2ms
memory: 3420kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabdcbeadaaa
result:
ok
Test #3:
score: 0
Accepted
time: 3ms
memory: 4160kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #5:
score: 0
Accepted
time: 3ms
memory: 4428kb
input:
23 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqq...
output:
abcdefagghijklmnoprstuuuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #6:
score: 0
Accepted
time: 1ms
memory: 4060kb
input:
22 500 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...
output:
aabbdefffghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #7:
score: -100
Wrong Answer
time: 0ms
memory: 3328kb
input:
30 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
aajyabmpqravasaaual*
result:
FAIL Wrong answer: does not fit word 0