QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#643096#8935. Puzzle: Easy as ScrabbleWolamWA 17ms4648kbC++209.8kb2024-10-15 18:45:532024-10-15 18:45:54

Judging History

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

  • [2024-10-15 18:45:54]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:4648kb
  • [2024-10-15 18:45:53]
  • 提交

answer

#include<bits/stdc++.h>
#define endl "\n"
using namespace std;
using ll = long long;
const int maxn = 1e3 + 10;
char D[maxn],U[maxn],L[maxn],R[maxn];
char maze[maxn][maxn];
bool valid=true;
void add(int type,int pos,int dir,int l,int r)//dir[1,4],pos[1,2] type[1,2]
{
    if(dir<=2)//up or down
    {
        if(dir==1)//up
        {
            if(D[pos]=='.')
            {
                return;
            }
            for(int i=r;i>=l;i--)
            {
                if(type==1)//left
                {
                    if(maze[i][pos]==D[pos])
                    {
                        break;
                    }
                    if((L[i]=='.'||L[i]==D[pos])&&(maze[i][pos]=='.'))
                    {
                        maze[i][pos]=D[pos];
                        L[i]='.';
                        D[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[i][pos]!='.'&&maze[i][pos]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[i][pos]='x';
                        }
                    }
                }
                else//right
                {
                    if(maze[i][pos]==D[pos])
                    {
                        break;
                    }
                    if((R[i]=='.'||R[i]==D[pos])&&(maze[i][pos]=='.'))
                    {
                        maze[i][pos]=D[pos];
                        R[i]='.';
                        D[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[i][pos]!='.'&&maze[i][pos]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[i][pos]='x';
                        }
                    }
                }
            }
        }
        else//down
        {
            if(U[pos]=='.')
            {
                return;
            }
            for(int i=l;i<=r;i++)
            {
                if(type==1)//left
                {
                    if(maze[i][pos]==U[pos])
                    {
                        break;
                    }
                    if((L[i]=='.'||L[i]==U[pos])&&(maze[i][pos]=='.'))
                    {
                        maze[i][pos]=U[pos];
                        L[i]='.';
                        U[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[i][pos]!='.'&&maze[i][pos]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[i][pos]='x';
                        }
                    }
                }
                else//right
                {
                    if(maze[i][pos]==U[pos])
                    {
                        break;
                    }
                    if((R[i]=='.'||R[i]==U[pos])&&(maze[i][pos]=='.'))
                    {
                        maze[i][pos]=U[pos];
                        R[i]='.';
                        U[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[i][pos]!='.'&&maze[i][pos]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[i][pos]='x';
                        }
                    }
                }
            }
        }
    }
    else//left or right
    {
        if(dir==3)//left
        {
            if(R[pos]=='.')
            {
                return;
            }
            for(int i=r;i>=l;i--)
            {
                if(type==1)//up
                {
                    if(maze[pos][i]==R[pos])
                    {
                        break;
                    }
                    if((U[i]=='.'||U[i]==R[pos])&&(maze[pos][i]=='.'))
                    {
                        maze[pos][i]=R[pos];
                        U[i]='.';
                        R[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[pos][i]!='.'&&maze[pos][i]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[pos][i]='x';
                        }
                    }
                }
                else//down
                {
                    if(maze[pos][i]==R[pos])
                    {
                        break;
                    }
                    if((D[i]=='.'||D[i]==R[pos])&&(maze[pos][i]=='.'))
                    {
                        maze[pos][i]=R[pos];
                        D[i]='.';
                        R[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[pos][i]!='.'&&maze[pos][i]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[pos][i]='x';
                        }
                    }
                }
            }
        }
        else//right
        {
            if(L[pos]=='.')
            {
                return;
            }
            for(int i=l;i<=r;i++)
            {
                if(type==1)//up
                {
                    if(maze[pos][i]==L[pos])
                    {
                        break;
                    }
                    if((U[i]=='.'||U[i]==L[pos])&&(maze[pos][i]=='.'))
                    {
                        maze[pos][i]=L[pos];
                        U[i]='.';
                        L[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[pos][i]!='.'&&maze[pos][i]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[pos][i]='x';
                        }
                    }
                }
                else//down
                {
                    if(maze[pos][i]==L[pos])
                    {
                        break;
                    }
                    if((D[i]=='.'||D[i]==L[pos])&&(maze[pos][i]=='.'))
                    {
                        maze[pos][i]=L[pos];
                        D[i]='.';
                        L[pos]='.';
                        break;
                    }
                    else
                    {
                        if(maze[pos][i]!='.'&&maze[pos][i]!='x')
                        {
                            valid=false;
                        }
                        else
                        {
                            maze[pos][i]='x';
                        }
                    }
                }
            }
        }
    }
}
void color(int l1,int r1,int l2,int r2)//[r,c]
{
    if(l1>r1||l2>r2)
    {
        return;
    }
    add(1,l1,4,l2,r2);
    add(1,l2,2,l1,r1);
    add(2,r2,2,l1,r1);
    add(1,l1,3,l2,r2);
    add(2,r1,3,l2,r2);
    add(2,r2,1,l1,r1);
    add(1,l2,1,l1,r1);
    add(2,r1,4,l2,r2);
    for(int i=l1+1;i<=r1-1;i++)
    {
        if(L[i]!='.'&&maze[i][l2]=='.')
        {
            maze[i][l2]=L[i];
            L[i]='.';
        }
        if(R[i]!='.'&&maze[i][r2]=='.')
        {
            maze[i][r2]=R[i];
            R[i]='.';
        }
    }
    for(int i=l2+1;i<=r2-1;i++)
    {
        if(U[i]!='.'&&maze[l1][i]=='.')
        {
            maze[l1][i]=U[i];
            U[i]='.';
        }
        if(D[i]!='.'&&maze[r1][i]=='.')
        {
            maze[r1][i]=D[i];
            D[i]='.';
        }
    }
    color(l1+1,r1-1,l2+1,r2-1);
}
void solve(void)
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<=n+1;i++)
    {
        for(int j=0;j<=m+1;j++)
        {
            cin>>maze[i][j];
        }
    }
    for(int i=1;i<=m;i++)
    {
        U[i]=maze[0][i];
        D[i]=maze[n+1][i];
    }
    for(int i=1;i<=n;i++)
    {
        L[i]=maze[i][0];
        R[i]=maze[i][m+1];
    }
    color(1,n,1,m);
    if(valid)
    {
        for(int i=1;i<=n;i++)
        {
            if(L[i]!='.'||R[i]!='.')
            {
                cout<<"NO"<<endl;
                return;
            }
        }
        for(int i=1;i<=m;i++)
        {
            if(U[i]!='.'||D[i]!='.')
            {
                cout<<"NO"<<endl;
                return;
            }
        }
        cout<<"YES"<<endl;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                if(maze[i][j]=='x'||maze[i][j]=='.')
                {
                    cout<<'.';
                }
                else
                {
                    cout<<maze[i][j];
                }
            }
            cout<<endl;
        }
    }
    else
    {
        cout<<"NO"<<endl;
    }
}
int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

input:

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

output:

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

result:

ok Correct.

Test #2:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

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

output:

NO

result:

ok Correct.

Test #3:

score: 0
Accepted
time: 0ms
memory: 3708kb

input:

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

output:

YES
U.NX.
.O..X
M.N..
.VB.S
.I.HX

result:

ok Correct.

Test #4:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

10 10
.BAZEMIEKUJ.
A..........K
B..x.x.x..x.
K.........xT
A.x..x.....J
Hx....x....B
Q..x....x.xW
S...x......W
S...x.xxx..Z
...x......xZ
I..x..x.x.xR
.QKO.ID..RW.

output:

YES
.AZEMIEK..
B.......U.
K.......T.
A........J
.H.......B
Q.......W.
S........W
S.O.....Z.
QK...D..Z.
...II...R.

result:

ok Correct.

Test #5:

score: 0
Accepted
time: 0ms
memory: 3552kb

input:

5 10
.PTWIVVISPY.
T...x.x....Y
Xx.x.xx..x.K
P.x.xx.....K
S..........A
E.........xS
.SPEASDCYSA.

output:

YES
.TW.V.ISPY
.X.I.....K
P....V...K
SP.......A
..EASDCYS.

result:

ok Correct.

Test #6:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

10 5
.HVYN..
Y.x...C
V..x..B
H...x.Z
....xxN
....x.P
B.x...G
Fx.x..D
Txx..xK
E..x.xR
Sx....B
.EPSBD.

output:

YES
..YNC
.V..B
H...Z
..N..
....P
B...G
.F..D
..TK.
EP.R.
..SB.

result:

ok Correct.

Test #7:

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

input:

50 50
.YDOGQIDENEUMONVSGZNMNHLEZCXIRMK.OOCKJOKXXZDUFEMPXS.
Y.x...x.x.x..x..........x.......x......x.....x....xX
N.........x.....x.....x....x.x.xxxxx.x...x.........E
U.....x.....x....x......x.....x........x..........xS
...x......x........x..x.....x.x.x........x.x.x.....S
Q.....x.x..x..........x....x....

output:

YES
Y.OGQ.D.N.UM.NVSGZNMNHL.ZCXIRMK.OOCKJO.XXZDU.EMPX.
ND...I.E....O..........E..............K.....F...E.
U........E......................................S.
.................................................S
Q................................................L
F...........................................

result:

ok Correct.

Test #8:

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

input:

100 100
.NUXAMX.LNWZKRRKZIRNZVDJF.XRB.VEFQXHTGLGIKZYSRPPF.YGVTOSQCADEG.KYKH.NWWO.XDXJW.G.RBHABFLWHFVUNOLBHMKN.
U..x...x...x....xx........x.....x.....xxx..x..........x..x...x..xx..x..x..x............x.....x.....x.N
C...x.......x.............x....x.x.x..x........x..x.xx..x..xx.................x..........

output:

YES
.U.AMX.LNW.KRRK..RNZVDJF..RB.VE.QXHTG...KZ.SRPPF.YGVT.SQ.ADE..K..H..WW..X.XJW.G.RBHABF.WHFVU.OLBHM.N
.CX.......Z....ZI..............F......GI..Y..........O..C...G..YK..N..O..D..................N.....KO
.O...................................L...........................................................

result:

ok Correct.

Test #9:

score: 0
Accepted
time: 5ms
memory: 4144kb

input:

500 500
..FHFDLGFGHREQBGILNRAGJ.ERZSAFGLQ.ESEBI.ELKM.RENLNFQSPT.TXUEIKHHOQWABSELMOPGTFGTXGYMTSU.N.O.AX.OGNSWTFSLUIMTUX.RUCECKZCXOJNPTFVAJUJTF.LHXURYIQIJCVWDBVZ.ZXFRAT.XIPXTDCSLHJHSZCW.RMNUGPIHYUQYUYAY.NHCBU.JPMLG.DDXAJWKNZJVKNAWAJZAHW.FCBEVATZ.YZ.HQ..QPLFARSHNP..EDPIKLYLF.FIFXEXR.XSUORAP.CZPMJXPUS.W...

output:

YES
...FDL...HREQ..ILNRA...ERZSA.GL...SE.I..LK...ENLNFQS.T.TX.E.K.HOQWA.SE.M.PGTFG.XGY..SU...O.AX.OGNS.TFSLUIM.UX...CEC..CXOJNPT.VA..JTF.LHXURYIQI.CVWDB.Z..XFR.T..IPXTD..LHJHSZCW.RMNUGPIHYUQY.YA..N.CB..JPM.G.DD.AJW.NZJ...AWAJZAHW.FCB...T..YZ.HQ..Q.LFA.S.NP..EDPI.LYLF..IFXEX...SUO.AP.CZP.JXPUS.W.D.WU...

result:

ok Correct.

Test #10:

score: 0
Accepted
time: 17ms
memory: 4648kb

input:

1000 1000
.SKFDQ.AV.GPTHMF.PL.YOQRQOXDOF.XVZ.H.MYOJIYT.QZNJQI.ZZMAJ.OAWBJBRXFW.CLEPPKGGAWGTVBKOBL.GPCO.ML.DBL.A.RJ..GF.EHK.CDXLLTCBCL.CGYJBMUSPIN.QELGYW.JE..CFVQF.LVYLFHYJ.MY.FZ.RU.ODLAYTWIZQOQZXBW.BVD.RFPLHLEHAU.G.PLFWFUKA.RSG..AVU.SA.PWRGJYO.OXD..S.Z.LIIADT.YXH..NHWXY.R.YFLS.URIJGPPURZPPVHJFLMKTDT...

output:

YES
S.FDQ.AV.GPTHMF.P..YOQRQOXD.F.XV.....YO.IYT.QZ.JQI.ZZMAJ.OAWBJBRX...C.EPP.GGAWGT.B..BL.GPCO.ML.D.L.A.R...GF.E.K.CDXLLT.BCL.CGYJB.USPIN..EL..W.J...CFVQ..LV.LFHYJ.MY.FZ.R..ODLAYTWIZQO.ZX.W...D.R..LHLE.A..G.PLFWFUKA.R.G..A...SA..WRGJ...OXD....Z.L.I.DT.Y.H..N.WXY.R.Y.LS..RI.G.PU.ZP.V..FLMKT.TWI.ZKHZ...

result:

ok Correct.

Test #11:

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

input:

1 1000
.K.CCS...LC.....Y..J...E.W.B..Q..KQ...Q...L..U.XSWX..NB..K.OLF...Y.A....HG....RRQO..Y...J.LOS...IN..C......H......X.....B.B.PQRT....VB.........P...E....MF.E...RH.XADCQN.D.KT.W..XNI..PH.Q.L.H..G...ZJR.V.I.......O......J.X..N..QS......UN....HLS..Z..N....X.YH.W..E.Z..JHSAV......YXT.P..TX.WT.SHE....

output:

NO

result:

wrong answer Jury has answer but participant has not.