QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#209465 | #5161. Last Guess | ucup-team1004 | WA | 1ms | 4224kb | C++14 | 3.1kb | 2023-10-10 15:16:10 | 2023-10-10 15:16:11 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
const int N=5e2+10,M=26,INF=1e9;
int n,m;
char a[N][N],b[N][N];
int must[N],ban[N][M],L[M],R[M],cnt[M],vis[M];
namespace Flow{
const int V=N+M,E=N*M*2+N*2+M*2+V*2;
int s,t,kk,head[V],d[V],cur[V];
struct edges{
int to,c,nex;
}edge[E];
void init(int x,int y){
s=x,t=y,kk=1;
fill(head+s,head+1+t,0);
}
bool chk(int i){
return !edge[i].c;
}
int add(int u,int v,int c){
// debug(u,v,c);
edge[++kk]={v,c,head[u]},head[u]=kk;
edge[++kk]={u,0,head[v]},head[v]=kk;
return kk-1;
}
bool bfs(){
queue<int>q;
q.push(s);
copy(head+s,head+1+t,cur+s);
fill(d+s,d+1+t,-1),d[s]=0;
for(int u;!q.empty();){
u=q.front(),q.pop();
for(int i=head[u];i;i=edge[i].nex){
int v=edge[i].to;
if(edge[i].c&&!~d[v])d[v]=d[u]+1,q.push(v);
}
}
return ~d[t];
}
int dfs(int u,int lim=INF){
if(u==t)return lim;
int flow=0;
for(int i=cur[u];i&&flow<lim;i=edge[i].nex){
cur[u]=i;
int v=edge[i].to,c=edge[i].c;
if(!c||d[v]!=d[u]+1)continue;
int f=dfs(v,min(lim-flow,c));
if(!f)d[v]=-1;
edge[i].c-=f,edge[i^1].c+=f,flow+=f;
}
return flow;
}
int dinic(){
int flow=0;
for(;bfs();)flow+=dfs(s);
return flow;
}
}
int k,s,t,S,T,id[N][M],p[N],q[M],deg[N];
int add(int u,int v,int l,int r){
// debug("edge",u,v,l,r);
deg[u]+=l,deg[v]-=l;
if(l==r)return 0;
return Flow::add(u,v,r-l);
}
int main(){
scanf("%d%d",&n,&m),n--;
fill(must+1,must+1+m,-1),fill(R,R+M,m);
for(int i=1;i<=n;i++){
scanf("%s%s",a[i]+1,b[i]+1);
fill(cnt,cnt+M,0),fill(vis,vis+M,0);
for(int j=1;j<=m;j++){
cnt[a[i][j]-'a']+=b[i][j]!='B';
vis[a[i][j]-'a']|=b[i][j]=='B';
if(b[i][j]=='G')must[j]=a[i][j]-'a';
else ban[j][a[i][j]-'a']=1;
}
for(int j=0;j<M;j++){
if(vis[j])L[j]=R[j]=cnt[j];
else L[j]=max(L[j],cnt[j]);
}
}
S=++k,s=++k;
for(int i=1;i<=m;i++)p[i]=++k;
for(int i=0;i<M;i++)q[i]=++k;
t=++k,T=++k;
// debug(S,T,s,t);
// debug(ary(p,1,m),ary(q,0,M-1));
Flow::init(S,T);
for(int i=1;i<=m;i++){
add(s,p[i],1,1);
if(~must[i])id[i][must[i]]=add(p[i],q[must[i]],0,1);
else{
for(int j=0;j<M;j++){
if(!ban[i][j])id[i][j]=add(p[i],q[j],0,1);
}
}
}
for(int i=0;i<M;i++){
add(q[i],t,L[i],R[i]);
}
add(t,s,0,INF);
for(int i=s;i<=t;i++){
if(deg[i]>0)Flow::add(i,T,deg[i]);
else if(deg[i]<0)Flow::add(S,i,-deg[i]);
}
// debug(ary(deg,S,T));
// for(int i=0;i<M;i++){
// debug(L[i],R[i]);
// }
Flow::dinic();
for(int i=1;i<=m;i++){
for(int j=0;j<M;j++){
if(id[i][j]&&Flow::chk(id[i][j])){
putchar(j+'a');break;
}
}
}
puts("");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3740kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3740kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabacabbzdde
result:
ok
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 4224kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzqzzzzzzzz...
result:
FAIL Condition failed: "answer.size() == n"