QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#201918#5161. Last GuessRd_rainydays#RE 1ms9756kbC++142.1kb2023-10-05 17:39:272023-10-05 17:39:27

Judging History

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

  • [2023-10-05 17:39:27]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:9756kb
  • [2023-10-05 17:39:27]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#define N 5005
using namespace std;
int n,m;
char s[N][N],t[N][N];
char ans[N],mp[N][N];
int ban[N];
int up[N],lw[N];
int cnt[N],aux[N];
vector<int> G[N];
int vis[N],match[N],col[N];
bool dfs(int x,int t){
   for(int y:G[x]){
    if(vis[y]!=t){
      vis[y]=t;
      if(!match[y]||dfs(match[y],t))return match[y]=x,true;
    }
   }
  return false;
}
int main(){
  scanf("%d%d",&n,&m);
  for(int i=1;i<n;i++){
    scanf("%s%s",s[i]+1,t[i]+1);
  }
  for(int i='a';i<='z';i++)up[i]=m,lw[i]=0;
  for(int i=1;i<n;i++){
    for(int r=1;r<=m;r++)if(t[i][r]=='G')ans[r]=s[i][r],ban[r]=1;
  }
  // for(int i=1;i<=m;i++)if(ban[i])aux[ans[i]]++;
  for(int i=1;i<n;i++){
    for(int r='a';r<='z';r++)cnt[r]=0;
    for(int r=1;r<=m;r++)if(ban[r]&&t[i][r]!='G')cnt[ans[r]]--;
    for(int r=1;r<=m;r++){
        if(t[i][r]=='Y'){
          cnt[s[i][r]]++;
          lw[s[i][r]]=max(lw[s[i][r]],cnt[s[i][r]]);
          mp[s[i][r]][r]=1;
        }
    }
    for(int r=1;r<=m;r++){
        if(t[i][r]=='B'){
          up[s[i][r]]=min(up[s[i][r]],cnt[s[i][r]]);
          mp[s[i][r]][r]=1;
        }
    }
  }
  // for(int i='a';i<='z';i++){
    // lw[i]-=aux[i],up[i]-=aux[i];
    // if(lw[i]!=0||up[i]!=m)cout<<(char)i<<" "<<lw[i]<<" "<<up[i]<<" "<<aux[i]<<endl;
  // }
  int idx=0;
  for(int i='a';i<='z';i++){
    for(int r=1;r<=lw[i];r++){
      idx++;col[idx]=i;
      for(int p=1;p<=m;p++){
        if(mp[i][p]==0&&ban[p]==0)G[idx].push_back(p);
      }
    }
  }
  int deg=0;
  for(int i=1;i<=idx;i++){
    deg+=int(dfs(i,i));
  }
  int tmpx=idx;
  for(int i='a';i<='z';i++){
    for(int r=lw[i]+1;r<=up[i];r++){
      idx++;col[idx]=i;
      for(int p=1;p<=m;p++){
        if(mp[i][p]==0&&ban[p]==0)G[idx].push_back(p);
      }
    }
  }
  for(int i=tmpx+1;i<=idx;i++)
  	deg+=int(dfs(i,i));
  
  // cout<<"debug:"<<idx<<" "<<deg<<endl;
  for(int i=1;i<=m;i++){
    if(ban[i])continue;
    if(match[i])ans[i]=(char)col[match[i]];
    else {
    	return -1;
		/*
      }*/ 
    }
  }
  puts(ans+1);

}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 9756kb

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

score: 0
Accepted
time: 1ms
memory: 7768kb

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabacaaadbed

result:

ok 

Test #3:

score: -100
Runtime Error

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:


result: