QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#602022#8935. Puzzle: Easy as Scrabbleracxa#WA 0ms3720kbC++144.0kb2024-09-30 17:53:502024-09-30 17:53:51

Judging History

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

  • [2024-09-30 17:53:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3720kb
  • [2024-09-30 17:53:50]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
using namespace std;
char g[1010][1010];
pair<int,char> pref[1010];
pair<int,char> suf[1010];
pair<int,char> top[1010];
pair<int,char> bot[1010];
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<=n+1;i++) {
        for(int j=0;j<=m+1;j++) {
            cin>>g[i][j];
        }
    }
    int indic=0;
    for(int i=1;i<=n;i++) {
        pref[i].ff=m+1;
        pref[i].ss='.';
        if(g[i][0]=='.') {
            pref[i].ff=0;
            pref[i].ss='.';
        }
        else {
            for(int j=1;j<=m;j++) {
                if(g[i][j]=='.') {
                    pref[i].ff=j;
                    pref[i].ss=g[i][0];
                    break;
                }
            }
        }
        suf[i].ff=0;
        suf[i].ss='.';
        if(g[i][m+1]=='.') {
            suf[i].ff=m+1;
            suf[i].ss='.';
        }
        else {
            for(int j=m;j>=1;j--) {
                if(g[i][j]=='.') {
                    suf[i].ff=j;
                    suf[i].ss=g[i][m+1];
                    break;
                }
            }
        }
        if(pref[i].ff>=suf[i].ff&&pref[i].ss!=suf[i].ss) {
            indic=1;
            break;
        }
    }

    if(indic==1) {
        cout<<"NO";
        return 0;
    }

    for(int j=1;j<=m;j++) {
        top[j].ff=n+1;
        top[j].ss='.';
        if(g[0][j]=='.') {
            top[j].ff=0;
            top[j].ss='.';
        }
        else {
            for(int i=1;i<=n;i++) {
                if(g[i][j]=='.') {
                    if(j<=pref[i].ff||j>=suf[i].ff) {
                        if(j<=pref[i].ff&&g[0][j]==g[i][0]||g[i][0]=='.') {
                            top[j].ff=i;
                            top[j].ss=g[0][j];
                            break;
                        }
                        if(j>=suf[i].ff&&g[0][j]==g[i][m+1]||g[i][m+1]=='.') {
                            top[j].ff=i;
                            top[j].ss=g[0][j];
                            break;
                        }
                    }
                    else {
                        top[j].ss=g[0][j];
                        top[j].ff=i;
                        break;
                    }
                }
            }
        }
        bot[j].ff=0;
        bot[j].ss='.';
        if(g[n+1][j]=='.') {
            bot[j].ff=n+1;
            bot[j].ss='.';
        }
        else {
            for(int i=n;i>=1;i--) {
                if(g[i][j]=='.') {
                    if(j<=pref[i].ff||j>=suf[i].ff){
                        if(j<=pref[i].ff&&g[n+1][j]==g[i][0]||g[i][0]=='.') {
                            bot[j].ff=i;
                            bot[j].ss=g[n+1][j];
                            break;
                        }
                        if(j>=suf[i].ff&&g[n+1][j]==g[i][m+1]||g[i][m+1]=='.') {
                            top[j].ff=i;
                            top[j].ss=g[n+1][j];
                            break;
                        }
                    }
                    else {
                        top[j].ss=g[n+1][j];
                        top[j].ff=i;
                        break;
                    }
                }
            }
        }
        if(top[j].ff>=bot[j].ff&&top[j].ss!=bot[j].ss) {
            indic=1;
            break;
        }
    }

    if(indic==1) {
        cout<<"NO";
        return 0;
    }

    for(int i=1;i<=n;i++) {
        g[i][pref[i].ff]=pref[i].ss;
        g[i][suf[i].ff]=suf[i].ss;
    }

    for(int j=1;j<=m;j++) {
        g[top[j].ff][j]=top[j].ss;
        g[bot[j].ff][j]=bot[j].ss;
    }

    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            if(g[i][j]=='x') {
                g[i][j]='.';
            }
            cout<<g[i][j];
        }
        cout<<endl;
    }


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3720kb

input:

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

output:

CBA..
....C
A...B
B...A
C....

result:

wrong answer YES or NO expected in answer, but CBA.. found.