QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#270850 | #5161. Last Guess | ckiseki# | WA | 2ms | 4756kb | C++20 | 3.9kb | 2023-12-01 16:32:01 | 2023-12-01 16:32:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
#include <experimental/iterator>
void debug_(auto s, auto ...a) {
cerr << "\e[1;32m(" << s << ") = (";
int f = 0;
(..., (cerr << (f++ ? ", " : "") << a));
cerr << ")\e[0m\n";
}
void orange_(auto s, auto L, auto R) {
cerr << "\e[1;33m[ " << s << " ] = [ ";
using namespace experimental;
copy(L, R, make_ostream_joiner(cerr, ", "));
cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif
template <typename Cap = int64_t> class Dinic {
private:
struct E { int to, rev; Cap cap; };
int n, st, ed;
vector<vector<E>> G;
vector<size_t> lv, idx;
vector<pair<int, int>> egs;
bool BFS() {
lv.assign(n, 0);
idx.assign(n, 0);
queue<int> bfs;
bfs.push(st);
lv[st] = 1;
while (not bfs.empty()) {
int u = bfs.front(); bfs.pop();
for (auto e : G[u]) if (e.cap > 0 and not lv[e.to])
bfs.push(e.to), lv[e.to] = lv[u] + 1;
}
return lv[ed];
}
Cap DFS(int u, Cap f = numeric_limits<Cap>::max()) {
if (u == ed) return f;
Cap ret = 0;
for (auto &i = idx[u]; i < G[u].size(); ++i) {
auto &[to, rev, cap] = G[u][i];
if (cap <= 0 or lv[to] != lv[u] + 1)
continue;
Cap nf = DFS(to, min(f, cap));
ret += nf; cap -= nf; f -= nf;
G[to][rev].cap += nf;
if (f == 0) return ret;
}
if (ret == 0) lv[u] = 0;
return ret;
}
public:
Dinic(int n_) : n(n_), G(n) {}
void add_edge(int u, int v, Cap c) {
G[u].push_back({v, int(G[v].size()), c});
G[v].push_back({u, int(G[u].size()) - 1, 0});
egs.emplace_back(v, int(G[v].size()) - 1);
}
Cap max_flow(int s, int e) {
st = s, ed = e;
Cap ret = 0;
while (BFS()) ret += DFS(st);
return ret;
}
Cap get(int id) {
return G[egs[id].first][egs[id].second].cap;
}
};
vector<int> flows(vector<tuple<int, int, int, int>> e, int s, int t, int n) {
const int S = n, T = n + 1;
vector<int64_t> in(n);
Dinic<int64_t> flow(n + 2);
for (auto [u, v, lb, ub] : e) {
flow.add_edge(u, v, ub - lb);
in[v] += lb;
in[u] -= lb;
}
for (int i = 0; i < n; ++i) {
if (in[i] > 0)
flow.add_edge(S, i, in[i]);
else
flow.add_edge(i, T, -in[i]);
}
flow.add_edge(t, s, n);
flow.max_flow(S, T);
flow.max_flow(s, t);
vector<int> out(e.size());
for (int i = 0; i < int(e.size()); ++i)
out[i] = get<2>(e[i]) + flow.get(i);
return out;
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int l, n;
cin >> l >> n;
vector<pair<string, string>> a(l - 1);
for (auto &[s, r] : a)
cin >> s >> r;
vector<tuple<int, int, int, int>> egs;
const int S = 26 + n, T = 26 + n + 1;
for (int i = 0; i < n; ++i)
egs.emplace_back(26 + i, T, 1, 1);
vector<tuple<size_t, int, char>> chk;
for (int i = 0; i < 26; ++i) {
vector<int> state(n);
int lb = 0, rb = n;
for (const auto &[s, r] : a) {
int cnt = 0;
for (int j = 0; j < n; ++j) {
if (s[j] != 'a' + i)
continue;
if (r[j] == 'G') {
state[j] = 1;
cnt++;
} else if (r[j] == 'Y') {
state[j] = -1;
cnt++;
} else {
rb = cnt;
}
}
lb = max(lb, cnt);
}
egs.emplace_back(S, i, lb, rb);
for (int j = 0; j < n; ++j) {
if (state[j] == 1) {
chk.emplace_back(egs.size(), j, 'a' + i);
egs.emplace_back(i, 26 + j, 1, 1);
} else if (state[j] == 0) {
chk.emplace_back(egs.size(), j, 'a' + i);
egs.emplace_back(i, 26 + j, 0, 1);
}
}
}
auto res = flows(egs, S, T, n + 26 + 2);
string ans(n, '.');
for (auto [i, p, c] : chk) {
if (res[i])
ans[p] = c;
}
cout << ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3684kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3716kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabdcbeadaaa
result:
ok
Test #3:
score: 0
Accepted
time: 2ms
memory: 4716kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
abcdefghijklmnaooprstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaoaaaaaaaa...
result:
ok
Test #4:
score: 0
Accepted
time: 2ms
memory: 4740kb
input:
24 500 vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #6:
score: 0
Accepted
time: 2ms
memory: 4736kb
input:
22 500 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...
output:
aabbdefffghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
30 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
vaylabmpqravasaaualj
result:
ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
31 20 azzzzzzzzzzzzzzzzzzz GBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BYBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBYBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBGBBBBBBBBBBBBB ...
output:
avqduiasiaafbuddayya
result:
ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
38 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBGBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
sawaaooaaaeakaahaaal
result:
ok
Test #10:
score: 0
Accepted
time: 2ms
memory: 4376kb
input:
25 500 eppppsppppppappppapppaswppspwppeupppwpwppppwppspppppppapppppspppappwpppppspspuppppppppppupwppeppppppppuppppusppspppppppwppppppppspeppppppppppepspppeppuppppwpppppppppppppwpppppppwppupppppspppppppppppppupeppppppppsppppeppaeppppppppppppppppppappppppppppppppppsppwppuappppepupuapppeppppppapppppppp...
output:
vayjogcjsnarhzfrshqbxhgirsgmitjvlabdikinenuizmgwwuqtzohxzeudgtmnhsaiacratgwgjljtkyetowdwlaibdvksccbsonlmrdjlgbngconrstmidytrdknwgjvyxzueqskrnvqgzmtvaelfxubiaqctbexjeftotinkqfsusinolqbsxjgcrqwkerywwmyylevubemsnzagqjtuvcuhvrbcnfcxznfymkquskbhffkcxrezezkemfyfgfzirxlhanfbvrldlhfcavqzzcbyhycwtknftnxhomqg...
result:
ok
Test #11:
score: 0
Accepted
time: 2ms
memory: 4444kb
input:
25 500 smxeetdiacxotgkpibsieraggqfjdbjxykzpiinrjxkmcczngkgpidtnacrzonzmrjsyfaiptigawddifgqxiiqibyymxvzncvifqsyfxmeodqwvwgqegpizkzfvsyywomkaviwjcasacijfbpjibvsroitinpfddjzcdkmxeisynrzipizmoyveveqwsfaqixobgrkstwtdtcfbwrvyvrgwdcmjozmitwcfitpzqdnikqbcpzyerwwigzdiczfmagmvacqxwbbiiiqrgxwvprvicjdsajinpmrrn...
output:
lxrggumnthrcukqbzoljgstkkayvmovrpqfbjjwsvrqxhhfwkqkbnmuwthsfcwfxsvlpytjbuzktdmmnykarnnanoppxrefwhejyalpyrxgcmadedkagkbnfqfyelppdcxqtendvhtlthnvyobvzoelscnuzwbymmvfhmqxrgnlpwsfjbjfxcpegegadlytajrcoksqludumuhyodsepeskdmhxvcfxjudhyzubfamwnqaohbfpgsddzkfmjhfyxtkxethardoojjzaskrdebsenhvmltvzwbxsswengqqwz...
result:
ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 4440kb
input:
25 500 zzzzzzzzzzezzzzzyzzzyfzzzzzyzfzzzzzuzzzzzzzzyezezzzyzzzzzzzzzzzzzzzuzzzzzzzzfzzzzzzzyzzezfzzzzzzzzzzzzzzzzzzzzzzzfzzzzzzzzzzzzzzuzzzzzzzzzzzzzzzzzzzzuzzzzzzzzzzzyzzzzuzzzzzzzyyzzzzzzzzzzzzzzzzzfzzzzzzzzzzyzzzzyzzzzzzeezzzzzzzzzzyzzzzzzzyzezzzfefzuzzzzzzzzzzzzzuzfzzzzzzezzzfzzzzzzzzzzyuezzfzzz...
output:
qjtwjfaynbvccrdxmkyemidubqxmbidthnhseryxlaeymvbvdqgmjplbtulcjwhffjcsftewuqbxixoaeklqmfcvjiyeuthdcnfrqlwcoynrwjtxyinarlkxyfwkcjwxsqbcldqgnhuohjjbalwyasdpgxqdrbenwmyonrsplnurofmmjjfkxwoqabotkkoatikpndnkqcqxmlpggmanbphuvvttrwehopqgmkreelbdmyvrhgivicskkpqgklfpyytlsxixrlogyvqanirnpjbxexfdmsvgfiepdgrsdfgd...
result:
ok
Test #13:
score: -100
Wrong Answer
time: 1ms
memory: 4600kb
input:
26 500 ffafffffafffffffffffffaaffaffffffffffffffffffffffffafffaffafffffffafffffffffffffffffffffffafaffffffffffafffffafffffffffafaffffffffffffffffffffaffffffffffffffffaffaffffffffffffffaffffffffffafffffafffaaffffffafafffafffffffffffffffaaffffffafffffffffffafffffffffffafffffafffffffaffffffffffafafffff...
output:
jlfbhgclfgttbbeeebcccccccccccbbbbbbbbbbbbbbbbbbbbbcccccdddddddddddddddddeeeeeeeeeeefffffffffffffffffffffffffffggggggggggggggghhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkkllllllllllllllllmmmmmmmmmmmmmmmmmnnnnnnnnnnnnnnnnnnnnnooooooooooooooooooooooppppppppppppppppppp...
result:
FAIL Wrong answer: does not fit word 0