QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661768#8935. Puzzle: Easy as ScrabbleDBsoleil#WA 1ms5984kbC++233.8kb2024-10-20 18:02:252024-10-20 18:02:26

Judging History

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

  • [2024-10-20 18:02:26]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5984kb
  • [2024-10-20 18:02:25]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define fi first 
#define se second 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=5005;
int k,n,m;
char g[N][N],ans[N][N];

void input()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<=n+1;i++) scanf("%s",g[i]);
    for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) ans[i][j]=g[i][j];
}

int check(char&x,char&y)
{
    if(x=='.'||y=='.') return x+y-'.';
    return x==y?x:-1;
}

bool fillrow(int x,int l,int r,int a,int b)
{
    //if(x==3) cerr<<x<<' '<<l<<' '<<a<<' '<<b<<endl;
    if(l>r) return 1;
    if(g[x][0]!='.')
    {
        while(l<=r&&(ans[x][l]=='x'||check(g[x][0],g[a][l])==-1||check(g[x][0],g[b][l])==-1)) ans[x][l]='.',l++;
        if(l<=r) ans[x][l]=g[x][0],g[x][0]=g[a][l]=g[b][l]='.'; else return 0;
    }
    if(g[x][m+1]!='.')
    {
        while(l<=r&&(ans[x][r]=='x'||check(g[x][m+1],g[a][r])==-1||check(g[x][m+1],g[b][r])==-1)) ans[x][r]='.',r--;
        if(l==r)
        {
            if(ans[x][l]!=g[x][m+1]) return 0;
            g[x][m+1]='.'; return 1;
        }
        if(l<=r) ans[x][r]=g[x][m+1],g[x][m+1]=g[a][r]=g[b][r]='.'; else return 0;
    }
    if(l==r&&check(g[x][l],g[x][r])==-1) return 0;
    for(int i=l+1;i<r;i++) 
    {
        if(ans[x][i]=='x'||check(g[a][i],g[b][i])==-1) continue;
        ans[x][i]=check(g[a][i],g[b][i]),g[a][i]=g[b][i]='.';
    }
    return 1;
}

bool fillcolumn(int x,int u,int d,int a,int b)
{
    //cerr<<x<<' '<<u<<' '<<d<<' '<<a<<' '<<b<<endl;
    if(u>d) return 1;
    if(g[0][x]!='.')
    {
        while(u<=d&&(ans[u][x]=='x'||check(g[0][x],g[u][a])==-1||check(g[0][x],g[u][b])==-1)) ans[u][x]='.',u++;
        if(u<=d) ans[u][x]=g[0][x],g[0][x]='.'; else return 0;
    }
    if(g[n+1][x]!='.')
    {
        while(u<=d&&(ans[d][x]=='x'||check(g[n+1][x],g[d][a])==-1||check(g[n+1][x],g[d][b])==-1)) ans[d][x]='.',d--;
        if(u==d)
        {
            if(ans[u][x]!=g[n+1][x]) return 0;
            g[n+1][x]='.'; return 1;
        }
        //cerr<<'!'<<g[d][a]<<' '<<char(check(g[n+1][x],g[d][a]))<<' '<<char(check(g[n+1][x],g[d][b]))<<endl;
        if(u<=d) ans[d][x]=g[n+1][x],g[n+1][x]='.'; else return 0;
    }
    if(u==d&&check(g[0][x],g[n+1][x])==-1) return 0;
    //cerr<<' '<<u<<' '<<d<<endl;
    for(int i=u+1;i<d;i++)
    {
        if(ans[i][x]=='x'||check(g[i][a],g[i][b])==-1) continue;
        ans[i][x]=check(g[i][a],g[i][b]),g[i][a]=g[i][b]='.';
    }
    return 1;
}

void update(char&x,char&y,char&ans)
{
    if(ans=='x') return;
    if(check(x,y)==-1) ans='.';
    else ans=check(x,y),x=y='.';
}

bool fillin(int u,int d,int l,int r)
{
    update(g[u][0],g[0][l],ans[u][l]);
    update(g[u][m+1],g[0][r],ans[u][r]);
    update(g[d][0],g[n+1][l],ans[d][l]);
    update(g[d][m+1],g[n+1][r],ans[d][r]);
    if(!fillrow(u,l+1,r-1,0,0)) return 0;
    if(!fillrow(d,l+1,r-1,n+1,n+1)) return 0;
    if(!fillcolumn(l,u+1,d-1,0,0)) return 0;
    if(!fillcolumn(r,u+1,d-1,m+1,m+1)) return 0;
    return 1;
}

bool work()
{
    int u=1,d=n,l=1,r=m;
    while(u<=d&&l<=r)
    {
        //cerr<<' '<<u<<' '<<d<<' '<<l<<' '<<r<<endl;
        if(u==d) return fillrow(u,l,r,0,n+1);
        if(l==r) return fillcolumn(l,u,d,0,m+1);
        if(!fillin(u,d,l,r)) return 0;
        else u++,d--,l++,r--;
    }
    return 1;
}

bool check()
{
    for(int i=1;i<=n;i++) if(g[i][0]!='.'||g[i][m+1]!='.') return 0;
    for(int i=1;i<=m;i++) if(g[0][i]!='.'||g[n+1][i]!='.') return 0;
    return 1;
}

void solve()
{
    input();
    if(!work()||!check()) {printf("NO\n"); return;}
    printf("YES\n");
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(ans[i][j]=='x') ans[i][j]='.';
            printf("%c",ans[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 5
.CBA...
....x..
..x...C
A.....B
B..x..A
C......
.......

output:

YES
C.A..
...C.
AB..B
.B.A.
C....

result:

ok Correct.

Test #2:

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

input:

1 2
....
Nx..
..O.

output:

NO

result:

ok Correct.

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 5984kb

input:

5 5
.U.N.X.
U....xX
Ox....X
M...xxN
Vx....S
Ix.x..X
..IBHX.

output:

NO

result:

wrong answer Jury has answer but participant has not.