QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#148971 | #5161. Last Guess | LaStataleBlue# | WA | 39ms | 4640kb | C++23 | 5.4kb | 2023-08-23 21:11:59 | 2023-08-23 21:12:01 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define f first
#define s second
template<class T> using V = vector<T>;
using vi = V<int>;
using vpi = V<pair<int,int>>;
#define sz(x) int((x).size())
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define each(a,x) for (auto& a: x)
#define all(x) begin(x), end(x)
template<class T> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0; } // set $a = \min(a,b)$
struct MCMF { // 0-based, archi direzionati
using F = ll; using C = ll; // flow type, cost type
struct Edge { int to, rev; F flo, cap; C cost; };
int N; V<C> p, dist; vpi pre; V<V<Edge>> adj;
void init(int _N) { N = _N;
p.resize(N),adj.resize(N),dist.resize(N),pre.resize(N);}
void ae(int u, int v, F cap, C cost) { assert(cap >= 0);
adj[u].pb({v,sz(adj[v]),0,cap,cost});
adj[v].pb({u,sz(adj[u])-1,0,0,-cost});
}
//send flow through lowest cost path
bool path(int s, int t) {
const C inf = numeric_limits<C>::max();
dist.assign(N,inf);
using T = pair<C,int>;
priority_queue<T,V<T>,greater<T>> todo;//(or queue<T>)
todo.push({dist[s] = 0,s});
while (sz(todo)) { // Dijkstra (or SPFA)
T x = todo.top(); todo.pop(); //(or todo.front())
if (x.f > dist[x.s]) continue; //(or x.f = dist[x.s])
//all weights should be non-negative
each(e,adj[x.s]) {
if (e.flo < e.cap && ckmin(dist[e.to],
x.f+e.cost+p[x.s]-p[e.to])) {
pre[e.to]={x.s,e.rev};
todo.push({dist[e.to],e.to});
}
}
} // if costs are doubles, add some EPS so you
// don't traverse ~0-weight cycle repeatedly
return dist[t] != inf; // true if augmenting path
}
pair<F,C> calc(int s, int t) { assert(s != t);
//F0R(_,N)F0R(i,N)each(e,adj[i])//utile con grafi densi...
// if(e.cap)ckmin(p[e.to],p[i]+e.cost);//e archi negativi
F totFlow = 0; C totCost = 0;
while (path(s,t)) { // p -> potentials for Dijkstra
F0R(i,N)p[i]+=dist[i];//don't matter for unreachable
F df = numeric_limits<F>::max();
for (int x = t; x != s; x = pre[x].f) {
Edge& e = adj[pre[x].f][adj[x][pre[x].s].rev];
ckmin(df,e.cap-e.flo); }
totFlow += df; totCost += (p[t]-p[s])*df;
for (int x = t; x != s; x = pre[x].f) {
Edge& e = adj[x][pre[x].s]; e.flo -= df;
adj[pre[x].f][e.rev].flo += df;
}
} // get max flow you can send along path
return {totFlow,totCost};
}
};
const int ALPHA = 26;
void solve(int t){
int g,l;
cin>>g>>l;
vector<int> low(ALPHA,0),up(ALPHA,l+1),found(l,-1);
vector<vector<bool>> ok(l,vector<bool>(ALPHA,true));
for(int i=0;i+1<g;i++){
string s,t;
cin>>s>>t;
vector<int> b(ALPHA),y(ALPHA);
for(int j=0;j<l;j++){
if(t[j]=='G'){
found[j]=s[j]-'a';
y[s[j]-'a']=true;
}else if(t[j]=='B'){
b[s[j]-'a']=true;
}else{
y[s[j]-'a']=true;
}
}
for(int j=0;j<ALPHA;j++){
if(b[j]){
int cont=0;
for(int k=0;k<l;k++){
if(s[k]-'a'==j && t[k]!='B'){
cont++;
if(t[k]=='Y'){
ok[k][j]=false;
}
}
}
up[j]=cont;
}
if(y[j]){
int cont=0;
for(int k=0;k<l;k++){
if(s[k]-'a'==j && t[k]!='B'){
cont++;
if(t[k]=='Y'){
ok[k][j]=false;
}
}
}
low[j]=max(low[j],cont);
}
}
}
MCMF ds;
ds.init(l+ALPHA+2);
int source = l+ALPHA, sink = l+ALPHA+1;
for(int i=0;i<ALPHA;i++){
ds.ae(source,l+i,low[i],0);
ds.ae(source,l+i,up[i]-low[i],1);
//cout<<low[i]<<" "<<up[i]<<"\n";
for(int j=0;j<l;j++){
if(found[j]!=-1){
if(i==found[j]){
ds.ae(l+i,j,1,0);
}
}else{
if(ok[j][i]){
ds.ae(l+i,j,1,0);
}
}
}
}
for(int i=0;i<l;i++){
ds.ae(i,sink,1,0);
}
auto res = ds.calc(source,sink);
//cout<<res.first<<" "<<res.second<<"\n";
vector<char> ans(l);
for(int i=0;i<l;i++){
for(auto j : ds.adj[i]){
//cout<<i<<" "<<j.to<<" "<<j.flo<<"\n";
if(j.to>=l && j.to<l+ALPHA && j.flo<0){
ans[i]=char(j.to-l+'a');
//cout<<i<<" "<<j.to<<" ecco\n";
}
}
}
for(int i=0;i<l;i++){
cout<<ans[i];
}
cout<<"\n";
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)solve(i);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 3580kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabacbegddaa
result:
ok
Test #3:
score: 0
Accepted
time: 30ms
memory: 4280kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
abcdefghijklmnaooprstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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qqqqgqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqgqqqqq...
output:
abcdefagghijklmnoprstuuuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #6:
score: 0
Accepted
time: 30ms
memory: 4220kb
input:
22 500 ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccoccccccccccccccccccccccccccccccccccccccccccccccccfccccccccccccccccccccccccccccccccc...
output:
aabbdefffghijklmnopqrstuvwxyzaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
result:
ok
Test #7:
score: 0
Accepted
time: 0ms
memory: 3596kb
input:
30 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
vajyablmqpavasaarauj
result:
ok
Test #8:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
31 20 azzzzzzzzzzzzzzzzzzz GBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BYBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBYBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBYBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBGBBBBBBBBBBBBB ...
output:
aydduiasdaafbiqvayua
result:
ok
Test #9:
score: 0
Accepted
time: 1ms
memory: 3568kb
input:
38 20 azzzzzzzzzzzzzzzzzzz YBBBBBBBBBBBBBBBBBBB zazzzzzzzzzzzzzzzzzz BGBBBBBBBBBBBBBBBBBB zzazzzzzzzzzzzzzzzzz BBYBBBBBBBBBBBBBBBBB zzzazzzzzzzzzzzzzzzz BBBGBBBBBBBBBBBBBBBB zzzzazzzzzzzzzzzzzzz BBBBGBBBBBBBBBBBBBBB zzzzzazzzzzzzzzzzzzz BBBBBYBBBBBBBBBBBBBB zzzzzzazzzzzzzzzzzzz BBBBBBYBBBBBBBBBBBBB ...
output:
kawaasoaaaeaoaahaaal
result:
ok
Test #10:
score: 0
Accepted
time: 39ms
memory: 4344kb
input:
25 500 eppppsppppppappppapppaswppspwppeupppwpwppppwppspppppppapppppspppappwpppppspspuppppppppppupwppeppppppppuppppusppspppppppwppppppppspeppppppppppepspppeppuppppwpppppppppppppwpppppppwppupppppspppppppppppppupeppppppppsppppeppaeppppppppppppppppppappppppppppppppppsppwppuappppepupuapppeppppppapppppppp...
output:
vayjogcjsnarhzfrshqbxhgirsgmitjvlabdikinenuizmgwwuqtzohxzeudgtmnhsaiacratgwgjljtkyetowdwlaibdvksccbsonlmrdjlgbngconrstmidytrdknwgjvyxzueqskrnvqgzmtvaelfxubiaqctbexjeftotinkqfsusinolqbsxjgcrqwkerywwmyylevubemsnzagqjtuvcuhvrbcnfcxznfymkquskbhffkcxrezezkemfyfgfzirxlhanfbvrldlhfcavqzzcbyhycwtknftnxhomqg...
result:
ok
Test #11:
score: 0
Accepted
time: 32ms
memory: 4440kb
input:
25 500 smxeetdiacxotgkpibsieraggqfjdbjxykzpiinrjxkmcczngkgpidtnacrzonzmrjsyfaiptigawddifgqxiiqibyymxvzncvifqsyfxmeodqwvwgqegpizkzfvsyywomkaviwjcasacijfbpjibvsroitinpfddjzcdkmxeisynrzipizmoyveveqwsfaqixobgrkstwtdtcfbwrvyvrgwdcmjozmitwcfitpzqdnikqbcpzyerwwigzdiczfmagmvacqxwbbiiiqrgxwvprvicjdsajinpmrrn...
output:
lxrggumnthrcukqbzoljgstkkayvmovrpqfbjjwsvrqxhhfwkqkbnmuwthsfcwfxsvlpytjbuzktdmmnykarnnanoppxrefwhejyalpyrxgcmadedkagkbnfqfyelppdcxqtendvhtlthnvyobvzoelscnuzwbymmvfhmqxrgnlpwsfjbjfxcpegegadlytajrcoksqludumuhyodsepeskdmhxvcfxjudhyzubfamwnqaohbfpgsddzkfmjhfyxtkxethardoojjzaskrdebsenhvmltvzwbxsswengqqwz...
result:
ok
Test #12:
score: 0
Accepted
time: 37ms
memory: 4404kb
input:
25 500 zzzzzzzzzzezzzzzyzzzyfzzzzzyzfzzzzzuzzzzzzzzyezezzzyzzzzzzzzzzzzzzzuzzzzzzzzfzzzzzzzyzzezfzzzzzzzzzzzzzzzzzzzzzzzfzzzzzzzzzzzzzzuzzzzzzzzzzzzzzzzzzzzuzzzzzzzzzzzyzzzzuzzzzzzzyyzzzzzzzzzzzzzzzzzfzzzzzzzzzzyzzzzyzzzzzzeezzzzzzzzzzyzzzzzzzyzezzzfefzuzzzzzzzzzzzzzuzfzzzzzzezzzfzzzzzzzzzzyuezzfzzz...
output:
qjtwjfaynbvccrdxmkyemidubqxmbidthnhseryxlaeymvbvdqgmjplbtulcjwhffjcsftewuqbxixoaeklqmfcvjiyeuthdcnfrqlwcoynrwjtxyinarlkxyfwkcjwxsqbcldqgnhuohjjbalwyasdpgxqdrbenwmyonrsplnurofmmjjfkxwoqabotkkoatikpndnkqcqxmlpggmanbphuvvttrwehopqgmkreelbdmyvrhgivicskkpqgklfpyytlsxixrlogyvqanirnpjbxexfdmsvgfiepdgrsdfgd...
result:
ok
Test #13:
score: -100
Wrong Answer
time: 30ms
memory: 4588kb
input:
26 500 ffafffffafffffffffffffaaffaffffffffffffffffffffffffafffaffafffffffafffffffffffffffffffffffafaffffffffffafffffafffffffffafaffffffffffffffffffffaffffffffffffffffaffaffffffffffffffaffffffffffafffffafffaaffffffafafffafffffffffffffffaaffffffafffffffffffafffffffffffafffffafffffffaffffffffffafafffff...
output:
jlfbhgclfgttbbeeebcccccccccccbbbbbbbbbbbbbbbbbbbbbcccccdddddddddddddddddeeeeeeeeeeefffffffffffffffffffffffffffggggggggggggggghhhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiijjjjjjjjjjjjjjjjjjjjjjkkkkkkkkkkkkkkkkkkkkkllllllllllllllllmmmmmmmmmmmmmmmmmnnnnnnnnnnnnnnnnnnnnnooooooooooooooooooooooppppppppppppppppppp...
result:
FAIL Wrong answer: does not fit word 0