QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#140871 | #5161. Last Guess | Gamal74 | WA | 3ms | 4496kb | C++20 | 4.4kb | 2023-08-16 21:55:55 | 2023-08-16 21:55:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define fi first
#define se second
#define pp push_back
#define all(x) (x).begin(), (x).end()
#define Ones(n) __builtin_popcount(n)
#define endl '\n'
#define mem(arrr, xx) memset(arrr,xx,sizeof arrr)
#define PI acos(-1)
//#define int long long
#define debug(x) cout << (#x) << " = " << x << endl
void Gamal() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifdef Clion
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
#endif
}
int dx[] = {+0, +0, -1, +1, +1, +1, -1, -1};
int dy[] = {-1, +1, +0, +0, +1, -1, +1, -1};
const double EPS = 1e-9;
const ll OO = 0X3F3F3F3F3F3F3F3F;
const int N = 500 + 5, INF = INT_MAX, MOD = 1e9 + 7, LOG = 20;
#define rep(aa, bb, cc) for(int aa = bb; aa < cc;aa++)
struct Dinic {
struct Edge {
int to, rev;
ll c, oc;
ll flow() { return max(oc - c, 0LL); } // if you need flows
};
vi lvl, ptr, q;
vector<vector<Edge>> adj;
Dinic(int n) : lvl(n), ptr(n), q(n), adj(n) {}
void addEdge(int a, int b, ll c, ll rcap = 0) {
adj[a].push_back({b, (int)adj[b].size(), c, c});
adj[b].push_back({a, (int)adj[a].size() - 1, rcap, rcap});
}
ll dfs(int v, int t, ll f) {
if (v == t || !f) return f;
for (int& i = ptr[v]; i < (int)adj[v].size(); i++) {
Edge& e = adj[v][i];
if (lvl[e.to] == lvl[v] + 1)
if (ll p = dfs(e.to, t, min(f, e.c))) {
e.c -= p, adj[e.to][e.rev].c += p;
return p;
}
}
return 0;
}
ll calc(int s, int t) {
ll flow = 0; q[0] = s;
rep(L,0,31) do { // 'int L=30' maybe faster for random data
lvl = ptr = vi((int)q.size());
int qi = 0, qe = lvl[s] = 1;
while (qi < qe && !lvl[t]) {
int v = q[qi++];
for (Edge e : adj[v])
if (!lvl[e.to] && e.c >> (30 - L))
q[qe++] = e.to, lvl[e.to] = lvl[v] + 1;
}
while (ll p = dfs(s, t, LLONG_MAX)) flow += p;
} while (lvl[t]);
return flow;
}
bool leftOfMinCut(int a) { return lvl[a] != 0; }
};
set<int>st[N];
int pos[30],mx[30];
string ans;
void go(){
string s, pat;
cin >> s >> pat;
int n = s.size();
vector<int>frq(26);
for (int i = 0; i < n; ++i) {
if(pat[i] != 'G'){
st[i].erase(s[i] - 'a');
if(pat[i] == 'Y')frq[s[i] - 'a']++;
if(pat[i] == 'B'){
mx[s[i] - 'a'] = min(mx[s[i] - 'a'],frq[s[i] - 'a']);
}
}
else {
frq[s[i] - 'a']++;
ans[i] = s[i];
}
}
for (int i = 0; i < 26; ++i) {
pos[i] = max(pos[i],frq[i]);
}
}
void solve() {
int g,l;
cin >> g >> l;
g--;
for (int i = 0; i < 26; ++i) {
pos[i] = 0;
mx[i] = l;
for (int j = 0; j < l; ++j) {
st[j].insert(i);
}
}
ans = string(l,'?');
for (int i = 0; i < g; ++i)go();
// 26 + l + 1 + 1
int src = 26 + l,src2 = src + 1,sink = src2 + 1;
Dinic flw(sink + 1);
int sum = 0;
for (int i = 0; i < l; ++i) {
if(ans[i] != '?'){
pos[ans[i] - 'a']--;
continue;
}
for(auto u:st[i]){
flw.addEdge(u,26+i,1);
}
flw.addEdge(26+i,sink,1);
}
for (int i = 0; i < 26; ++i) {
int low = pos[i],hi = mx[i];
sum += low;
flw.addEdge(src2,i,hi - low);
flw.addEdge(src,i,low);
flw.addEdge(src2,sink,low);
}
int cnt = 0;
for (int i = 0; i < l; ++i) {
cnt += ans[i] == '?';
}
flw.addEdge(src,src2,cnt);
flw.addEdge(src,sink,cnt);
flw.calc(src,sink);
for (int i = 0; i < 26; ++i) {
for(auto &e:flw.adj[i]){
if(e.flow() && e.to >= 26 && e.to < l + 26){
ans[e.to - 26] = i + 'a';
}
}
}
cout << ans;
}
signed main() {
Gamal();
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabdcbeadaaa
result:
ok
Test #3:
score: 0
Accepted
time: 3ms
memory: 4424kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
abcdefghijklmnaooprstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaoaaaaaaaa...
result:
ok
Test #4:
score: 0
Accepted
time: 3ms
memory: 4368kb
input:
24 500 vvvvvvvvvvvvvv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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #6:
score: 0
Accepted
time: 3ms
memory: 4496kb
input:
22 500 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...
output:
aabbdefffghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 3656kb
input:
30 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
vajlabmpqravasaauabj
result:
FAIL Wrong answer: does not fit word 21