QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322096#5161. Last GuesswangqingxianWA 2ms11980kbC++143.8kb2024-02-06 11:01:322024-02-06 11:01:33

Judging History

你现在查看的是最新测评结果

  • [2024-02-06 11:01:33]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11980kb
  • [2024-02-06 11:01:32]
  • 提交

answer

//#pragma GCC optimize(2)
#include<algorithm>
#include<stdlib.h>
#include<iostream>
#include<cassert>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<cstdio>
#include<random>
#include<bitset>
#include<queue>
#include<cmath>
#include<set>
#include<map>
//#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define For(i,l,r) for(int i=(l);i<=(r);++i)
#define rof(i,r,l) for(int i=(r);i>=(l);--i)
#define mem0(a) memset(a,0,sizeof(a))
#define ckmax(a,b) a=max(a,b)
#define ckmin(a,b) a=min(a,b)
using namespace std;
template <int N> struct Flow{
    const int inf=1e9;
    int fst[N],nx[N],v[N],w[N],es=1,dis[N];
    int tot=0;
    inline void add_edge(int a,int b,int c){
        ++es;
        v[es]=b;w[es]=c;nx[es]=fst[a];fst[a]=es;
        ++es;
        v[es]=a;w[es]=0;nx[es]=fst[b];fst[b]=es;
    }
    inline bool bfs(int s,int t){
        For(i,1,tot)dis[i]=inf;
        queue<int>que;que.push(s);
        dis[s]=0;
        while(!que.empty()){
            int hd=que.front();
            que.pop();
            for(int i=fst[hd];i;i=nx[i]){
                int nxt=v[i];
                if(dis[nxt]==inf&&(w[i]>0)){
                    dis[nxt]=dis[hd]+1;
                    if(nxt==t)return 1;
                    que.push(nxt);
                }
            }
        }
        return 0;
    }
    int dfs(int x,int sum,int t){
        if(x==t)return sum;
        int res=0;
        for(int i=fst[x];i;i=nx[i]){
            int nxt=v[i];
            if(dis[nxt]==dis[x]+1&&(w[i]>0)){
                int k=dfs(nxt,min(sum,w[i]),t);
                if(!k)dis[nxt]=inf;
                w[i]-=k;w[i^1]+=k;
                sum-=k;res+=k;
                if(!sum)return res;
            }
        }
        return res;
    }
    inline int maxflow(int s,int t){
        int res=0;
        while(bfs(s,t))
            res+=dfs(s,inf,t);
        return res;
    }
};
Flow<(int)(1e6+10)> g;
const int N=2e3+10,inf=1e18,mod=1e9+7;
int n,len;
bool ed[30][N];
int R[30],L[30];
struct edge{
    int u,v,l,r;
};
vector<edge>e;
int h[N];
inline int solve(int s,int t,int tot){
    int ss=++tot,tt=++tot;
    g.tot=tot;
    g.es=1;
    for(auto [u,v,l,r]:e){
        g.add_edge(u,v,r-l);
        h[v]+=l;
        h[u]-=l;
    }
    g.add_edge(t,s,inf);
    For(i,1,tot){
        if(h[i]>0)g.add_edge(ss,i,h[i]);
        else if(h[i]<0)g.add_edge(i,tt,-h[i]);
    }
    g.maxflow(ss,tt);
    return g.maxflow(s,t);
}
signed main(){
    ios::sync_with_stdio(NULL);
    cin.tie(0);cout.tie(0);
    cin>>n>>len;
    For(i,0,25){
        L[i]=0;
        R[i]=len;
    }
    For(i,0,25)For(j,0,len-1)ed[i][j]=1;
    For(o,1,n-1){
        string s1,s2;
        cin>>s1>>s2;
        bool flag[30]={};
        int cnt[30]={};
        For(i,0,len-1){
            if(s2[i]=='B')flag[s1[i]-'a']=1;
            else ++cnt[s1[i]-'a'];
            if(s2[i]=='G'){
                For(j,0,25)ed[j][i]=0;
                ed[s1[i]-'a'][i]=1;
            }
            else ed[s1[i]-'a'][i]=0;
        }
        For(i,0,25){
            if(!flag[i])ckmax(L[i],cnt[i]);
            else L[i]=R[i]=cnt[i];
        }
    }
    int s=1,t=2,tot=2+26+len;
    For(i,0,25){
        e.push_back({s,i+2,L[i],R[i]});
    }
    For(i,0,25)For(j,0,len-1){
        if(ed[i][j]){
            e.push_back({i+2,j+2+26,0,1});
        }
    }
    For(i,0,len-1){
        e.push_back({i+2+26,t,0,1});
    }
    solve(s,t,tot);
    For(i,0,len-1){
        for(int j=g.fst[i+2+26];j;j=g.nx[j]){
            int nxt=g.v[j];
            if(g.w[j^1]==0&&nxt-2<26){
                cout<<(char(nxt-2+'a'));
                break;
            }
        }
    }
    cout<<endl;
    return 0;
}
/*
4 5
reply YYGBB
refer BBBGG
puppy YYGBB
 
2 12
aabbccddeeff GGGYGBYYYBBB
 */

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 11904kb

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

score: 0
Accepted
time: 2ms
memory: 11856kb

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabzczbbzdde

result:

ok 

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 11980kb

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:

zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzozzzzzzzz...

result:

FAIL Wrong answer: does not fit word 8