QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#540634 | #8935. Puzzle: Easy as Scrabble | ucup-team4508# | WA | 1ms | 5728kb | C++14 | 3.0kb | 2024-08-31 17:34:30 | 2024-08-31 17:34:31 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL n,i,j,k,m,t;
LL a[500005];
string s[1005];
string s1,s2,s3,s4;
LL stat[1005][1005];
LL tag1[1005],tag2[1005],tag3[1005],tag4[1005];
bool doit(LL stat,LL x){
if(stat==1){
LL tmp=tag1[x];
for(LL i=tmp+1;i<=n;i++){
if((s[i][x]=='.' && tag3[i]<=x && tag4[i]>=x) || s[i][x]==s1[x]){
s[i][x]=s1[x],s[tmp][x]='.',tag1[x]=i;return true;
}
else if(s[i][x]>='A' && s[i][x]<='Z'){
if(tag2[x]==i || (tag3[i]==x && tag4[i]==x)){
return false;
}
if(tag3[i]==x){
if(doit(3,i)==false) return false;
}
if(tag4[i]==x){
if(doit(4,i)==false) return false;
}
}
}
return false;
}
if(stat==2){
LL tmp=tag2[x];
for(LL i=tmp-1;i>=1;i--){
if((s[i][x]=='.' && tag3[i]<=x && tag4[i]>=x) || s[i][x]==s2[x]){
s[i][x]=s2[x],s[tmp][x]='.',tag2[x]=i;return true;
}
else if(s[i][x]>='A' && s[i][x]<='Z'){
if(tag1[x]==i || (tag3[i]==x && tag4[i]==x)){
return false;
}
if(tag3[i]==x){
if(doit(3,i)==false) return false;
}
if(tag4[i]==x){
if(doit(4,i)==false) return false;
}
}
}
return false;
}
if(stat==3){
LL tmp=tag3[x];
for(LL i=tmp+1;i<=n;i++){
if((s[x][i]=='.' && tag1[i]<=x && tag2[i]>=x) || s[x][i]==s3[x]){
s[x][i]=s3[x],s[x][tmp]='.',tag3[x]=i;return true;
}
else if(s[x][i]>='A' && s[x][i]<='Z'){
if(tag4[x]==i || (tag1[i]==x && tag2[i]==x)){
return false;
}
if(tag1[i]==x){
if(doit(1,i)==false) return false;
}
if(tag2[i]==x){
if(doit(2,i)==false) return false;
}
}
}
return false;
}
if(stat==4){
LL tmp=tag4[x];
for(LL i=tmp-1;i>=1;i--){
if((s[x][i]=='.' && tag1[i]<=x && tag2[i]>=x) || s[x][i]==s4[x]){
s[x][i]=s4[x],s[x][tmp]='.',tag4[x]=i;return true;
}
else if(s[x][i]>='A' && s[x][i]<='Z'){
if(tag3[x]==i || (tag1[i]==x && tag2[i]==x)){
return false;
}
if(tag1[i]==x){
if(doit(1,i)==false) return false;
}
if(tag2[i]==x){
if(doit(2,i)==false) return false;
}
}
}
return false;
}
return false;
}
int main(){
cin>>n>>m;
for(i=0;i<=n+1;i++)
cin>>s[i];
for(i=0;i<=n+1;i++){
s1+=s[0][i],s2+=s[n+1][i],s3+=s[i][0],s4+=s[i][n+1];
}
for(i=1;i<=n;i++)
tag2[i]=n+1,tag4[i]=n+1;
for(i=1;i<=n;i++){
if(s1[i]=='.') continue;
if(doit(1,i)==false){
printf("NO");
return 0;
}
}
for(i=1;i<=n;i++){
if(s2[i]=='.') continue;
if(doit(2,i)==false){
printf("NO");
return 0;
}
}
for(i=1;i<=n;i++){
if(s3[i]=='.') continue;
if(doit(3,i)==false){
printf("NO");
return 0;
}
}
for(i=1;i<=n;i++){
if(s4[i]=='.') continue;
if(doit(4,i)==false){
printf("NO");
return 0;
}
}
printf("YES\n");
for(i=1;i<=n;i++){
for(j=1;j<=n;j++)
printf("%c",s[i][j]);
printf("\n");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5728kb
input:
5 5 .CBA... ....x.. ..x...C A.....B B..x..A C...... .......
output:
YES CBAx. .x..C A...B B.x.A C....
result:
wrong answer Token parameter [name=row] equals to "CBAx.", doesn't correspond to pattern "[A-Z.]{5}"