QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#574417#8935. Puzzle: Easy as ScrabblechenhongxuanWA 13ms15776kbC++147.1kb2024-09-18 22:02:302024-09-18 22:02:31

Judging History

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

  • [2024-09-18 22:02:31]
  • 评测
  • 测评结果:WA
  • 用时:13ms
  • 内存:15776kb
  • [2024-09-18 22:02:30]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define lc p<<1
#define rc p<<1|1
#define pb push_back
#define pii pair<int,int>
#define st first
#define nd second
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar())f^=ch=='-';
    for(;isdigit(ch);ch=getchar())x=x*10+(ch^48);
    return f?x:-x;
}
mt19937 rnd(time(0));
const int mo=998244353;
inline int qpow(int x,int t){
    int ret=1;
    for(;t;t>>=1,x=x*x%mo)if(t&1)ret=ret*x%mo;
    return ret;
}
inline void red(int &x){x>=mo?x-=mo:0;}
inline void chmin(int &x,int y){x=min(x,y);}
inline void chmax(int &x,int y){x=max(x,y);}
const int N=1005;
char str[N][N],ff[N][N];
int n,m,tag[N][N],qd[N][N];
struct oper{
    int x,y,dx,dy;
    char c;
    pii type,ori;
};
vector<oper> op;
pii rev(pii t,int x,int y){
    if(t.st==-1)t.st=x;
    if(t.nd==-1)t.nd=y;
    return t;
}
void output(int t=0){
    for(int i=1;i<=n;++i,puts(""))for(int j=1;j<=m;++j){
        if(!ff[i][j])putchar('.');
        else putchar(ff[i][j]);
    }
    if(t==1){
        for(int i=1;i<=n;++i,puts(""))for(int j=1;j<=m;++j){
            printf("%lld ",qd[i][j]);
        }
    }
    if(t==2){
        for(int i=0;i<=n+1;++i,puts(""))for(int j=0;j<=m+1;++j){
            printf("%lld ",tag[i][j]);
        }
    }
}
int in(int x,int l,int r){return l<=x&&x<=r;}
void work(int i1,int i2,int j1,int j2){
    // printf("This is the :(%lld,%lld,%lld,%lld) work\n",i1,i2,j1,j2);
    if(i1>i2)return;
    if(j1>j2)return;
    op.clear();
    if(!tag[i1][0])op.pb(oper{i1,j1,0,1,str[i1][0],{0,-1},{i1,0}});
    if(!tag[i1][m+1])op.pb(oper{i1,j2,0,-1,str[i1][m+1],{0,-1},{i1,m+1}});
    if(!tag[i2][0])op.pb(oper{i2,j1,0,1,str[i2][0],{n+1,-1},{i2,0}});
    if(!tag[i2][m+1])op.pb(oper{i2,j2,0,-1,str[i2][m+1],{n+1,-1},{i2,m+1}});
    if(!tag[0][j1])op.pb(oper{i1,j1,1,0,str[0][j1],{-1,0},{0,j1}});
    if(!tag[n+1][j1])op.pb(oper{i2,j1,-1,0,str[n+1][j1],{-1,0},{n+1,j1}});
    if(!tag[0][j2])op.pb(oper{i1,j2,1,0,str[0][j2],{-1,m+1},{0,j2}});
    if(!tag[n+1][j2])op.pb(oper{i2,j2,-1,0,str[n+1][j2],{-1,m+1},{n+1,j2}});
    //recheck : so try again
    if(!tag[i1][0])op.pb(oper{i1,j1,0,1,str[i1][0],{0,-1},{i1,0}});
    if(!tag[i1][m+1])op.pb(oper{i1,j2,0,-1,str[i1][m+1],{0,-1},{i1,m+1}});
    if(!tag[i2][0])op.pb(oper{i2,j1,0,1,str[i2][0],{n+1,-1},{i2,0}});
    if(!tag[i2][m+1])op.pb(oper{i2,j2,0,-1,str[i2][m+1],{n+1,-1},{i2,m+1}});
    if(!tag[0][j1])op.pb(oper{i1,j1,1,0,str[0][j1],{-1,0},{0,j1}});
    if(!tag[n+1][j1])op.pb(oper{i2,j1,-1,0,str[n+1][j1],{-1,0},{n+1,j1}});
    if(!tag[0][j2])op.pb(oper{i1,j2,1,0,str[0][j2],{-1,m+1},{0,j2}});
    if(!tag[n+1][j2])op.pb(oper{i2,j2,-1,0,str[n+1][j2],{-1,m+1},{n+1,j2}});
    for(oper T:op){
        int x=T.x,y=T.y,dx=T.dx,dy=T.dy;
        char c=T.c;
        pii pos=T.type;
        int r=0;
        while(in(x,i1,i2)&&in(y,j1,j2)){
            if(ff[x][y]){
                if(ff[x][y]=='.'){
                    qd[x][y]=-1;
                    x+=dx;
                    y+=dy;
                    continue;
                }
                if(ff[x][y]==c)r=1;
                break;
            }
            else{
                pii tmp=rev(pos,x,y);
                if(tag[tmp.st][tmp.nd]||str[tmp.st][tmp.nd]==c){
                    ff[x][y]=c;
                    r=1;
                    break;
                }
                qd[x][y]=-1;
                x+=dx;
                y+=dy;
            }
        }
        if(!r){
            // puts("Oh NO!");
            // printf("get killed @ %lld %lld\n",T.ori.st,T.ori.nd);
            // output(1);
            return;
        }
    }
    for(auto T:op){
        tag[T.ori.st][T.ori.nd]=1;
    }
    // puts("First Work");
    // output(1);
    for(int i=i1+1;i<i2;++i){
        if(qd[i][j1]!=-1){
            if(ff[i][j1]){
                tag[i][0]|=(ff[i][j1]==str[i][0]);
            }
            else{
                if(!tag[i][0]){
                    ff[i][j1]=str[i][0];
                    tag[i][0]=1;
                }
            }
        }
    }
    for(int i=i1+1;i<i2;++i){
        if(qd[i][j2]!=-1){
            if(ff[i][j2]){
                tag[i][m+1]|=(ff[i][j2]==str[i][m+1]);
            }
            else{
                if(!tag[i][m+1]){
                    ff[i][j2]=str[i][m+1];
                    tag[i][m+1]=1;
                }
            }
        }
    }
    for(int j=j1+1;j<j2;++j){
        if(qd[i1][j]!=-1){
            if(ff[i1][j]){
                tag[0][j]|=(ff[i1][j]==str[0][j]);
            }
            else{
                if(!tag[0][j]){
                    ff[i1][j]=str[0][j];
                    tag[0][j]=1;
                }
            }
        }
    }
    for(int j=j1+1;j<j2;++j){
        if(qd[i2][j]!=-1){
            if(ff[i2][j]){
                tag[n+1][j]|=(ff[i2][j]==str[n+1][j]);
            }
            else{
                if(!tag[n+1][j]){
                    ff[i2][j]=str[n+1][j];
                    tag[n+1][j]=1;
                }
            }
        }
    }
    // puts("Second work");
    // output(2);
    work(i1+1,i2-1,j1+1,j2-1);
}
void solve(){
    n=read(),m=read();
    for(int i=0;i<=n+1;++i)scanf("%s",str[i]);
    for(int i=1;i<=n;++i){
        if(str[i][0]=='.')tag[i][0]=1;
        if(str[i][m+1]=='.')tag[i][m+1]=1;
    }
    for(int j=1;j<=m;++j){
        if(str[0][j]=='.')tag[0][j]=1;
        if(str[n+1][j]=='.')tag[n+1][j]=1;
    }
    for(int i=1;i<=n;++i)for(int j=1;j<=m;++j){
        if(str[i][j]=='x')ff[i][j]='.';
    }
    work(1,n,1,m);
    for(int i=1;i<=n;++i){
        if(!tag[i][0]){
            int r=1;
            for(int j=1;j<=m;++j){
                if(ff[i][j]!='.'&&ff[i][j]){
                    if(str[i][0]==ff[i][j])r=0;
                    break;
                }
            }
            if(r){puts("NO");return;}
        }
        if(!tag[i][m+1]){
            int r=1;
            for(int j=m;j>=1;--j){
                if(ff[i][j]!='.'&&ff[i][j]){
                    if(str[i][m+1]==ff[i][j])r=0;
                    break;
                }
            }
            if(r){puts("NO");return;}
        }
    }
    for(int j=1;j<=m;++j){
        if(!tag[0][j]){
            int r=1;
            for(int i=1;i<=n;++i){
                if(ff[i][j]!='.'&&ff[i][j]){
                    if(str[0][j]==ff[i][j])r=0;
                    break;
                }
            }
            if(r){puts("NO");return;}
        }
        if(!tag[n+1][j]){
            int r=1;
            for(int i=n;i>=1;--i){
                if(ff[i][j]!='.'&&ff[i][j]){
                    if(str[n+1][j]==ff[i][j])r=0;
                    break;
                }
            }
            if(r){puts("NO");return;}
        }
    }
    puts("YES");
    for(int i=1;i<=n;++i,puts(""))for(int j=1;j<=m;++j){
        if(!ff[i][j])putchar('.');
        else putchar(ff[i][j]);
    }
    return;
}
signed main(){
    // freopen("D.out","w",stdout);
    for(int cas=1;cas--;)solve();
    return 0;
}

详细

Test #1:

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

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: 1ms
memory: 7916kb

input:

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

output:

NO

result:

ok Correct.

Test #3:

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

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: 1ms
memory: 7920kb

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: 1ms
memory: 6028kb

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: 8068kb

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: 0ms
memory: 9884kb

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: 2ms
memory: 9876kb

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: 6ms
memory: 14160kb

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: 13ms
memory: 15776kb

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: 0
Accepted
time: 0ms
memory: 8016kb

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:

YES
K.CCS...LC.Y.W.Y..J...E.W.B..Q..KQ..EQD..LT.U.XSWX..NB..K.OLF...Y.A....HG.BH.RRQO..Y..PJ.LOSU..IN..C......H......X.....B.B.PQRT...QVB...V..K..P...E....MF.E...RH.XADCQN.D.KT.W..XNI..PH.Q.L.H..G..ZZJR.V.I.......O.....DJ.X..NC.QS......UN....HLS.TZ..N....X.YH.W..EBZZ.JHSAV......YXT.P..TX.WT.SHE...YG...

result:

ok Correct.

Test #12:

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

input:

2 1000
.D..JPYBD.H..F.I.NTFC.VJKS..Q.PBW..XLW.ZS..ATCTMPPKRK.V.NN.MPE.SPN.QODI.H...OR.V..INXOZMGF.KIS.GANJ.WV.YLALHHXO..M.TMTJ..XYP.N.BUENZCUA.I.XJO.Q.NVG.B.TXNI.TVLY.N.CWE.ZEO.ANYRZ.W.PQI.LORBYIYJIK.JZ.PENB.HPJPTIIGVOMF.RPZ..WFM.IS..H..U.ZEX.DXZU.YHM.UOMPOHV.HW..SZ.RHWXW.SZH.....R.X.R.L.JRYLL.CE.IE...

output:

NO

result:

wrong answer Jury has answer but participant has not.