QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201863 | #5161. Last Guess | Rd_rainydays# | WA | 1ms | 9984kb | C++14 | 2.0kb | 2023-10-05 17:09:08 | 2023-10-05 17:09:09 |
Judging History
answer
#include<bits/stdc++.h>
#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));
}
// cout<<"debug:"<<idx<<" "<<deg<<endl;
assert(deg==idx);
for(int i=1;i<=m;i++){
if(ban[i])continue;
if(match[i])ans[i]=(char)col[match[i]];
else {
for(int r='a';r<='z';r++){
if(lw[r]<up[r]&&mp[r][i]==0){
ans[i]=r;
lw[r]++;
break;
}
}
}
}
puts(ans+1);
}
/*
8 6
source GYBYBB
slower GBYBBY
slowly GBYBBB
sorted GYGYBB
scream GBGBBB
scattr GBBYBY
strooo GGGGBB
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 9984kb
input:
4 5 reply YYGBB refer BBBGG puppy YYGBB
output:
upper
result:
ok
Test #2:
score: 0
Accepted
time: 1ms
memory: 7832kb
input:
2 12 aabbccddeeff GGGYGBYYYBBB
output:
aabecdbadaaa
result:
ok
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 7924kb
input:
25 500 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...
output:
zyxwvutsrpooonmlkjihgfedcbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
result:
FAIL Condition failed: "answer.size() == n"