QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#357880#4432. Jungle Trailopen your brain (Zhi Zhang, Yanru Guan, Jianfeng Zhu)#AC ✓54ms23504kbC++171.3kb2024-03-19 14:15:092024-03-19 14:15:09

Judging History

This is the latest submission verdict.

  • [2024-03-19 14:15:09]
  • Judged
  • Verdict: AC
  • Time: 54ms
  • Memory: 23504kb
  • [2024-03-19 14:15:09]
  • Submitted

answer

#include <bits/stdc++.h>
#define No() return puts("NIE"),void();
using namespace std;
int n,m,f[2010][2010],t[4010];
char a[2010][2010],ans[4010];
int fx[2][2]={{0,-1},{-1,0}};
void sol(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) scanf("%s",a[i]+1);
    if(a[1][1]=='#') No();
    f[1][1]=1;
    for(int i=1;i<=n;i++) for(int j=1+(i==1);j<=m;j++){
        if(a[i][j]=='#') f[i][j]=0;
        else f[i][j]=f[i-1][j]|f[i][j-1];
    }
    if(!f[n][m]) No();
    int x=n,y=m,fxx=0,pre=0;
    for(int i=1;i<=n+m;i++) t[i]=0;
    while(1){
        int done=0;
        if(a[x][y]!='.'){
            int nw=pre^(a[x][y]=='@');
            if(nw){
                if(fxx) t[x]=1;
                else t[n+y]=1;
                done=1;
            }
        }
        if(x==1&&y==1) break;
        int xx=x+fx[fxx][0],yy=y+fx[fxx][1];
        if(xx<1||xx>n||yy<1||yy>m||!f[xx][yy]){
            fxx^=1,pre=done;
            xx=x+fx[fxx][0],yy=y+fx[fxx][1];
        }
        x=xx,y=yy;
        ans[x+y-1]=fxx?'D':'P';
    }
    puts("TAK");
    for(int i=1;i<=n;i++) putchar(t[i]?'T':'N');puts("");
    for(int i=1;i<=m;i++) putchar(t[n+i]?'T':'N');puts("");
    for(int i=1;i<=n+m-2;i++) putchar(ans[i]);puts("");
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--) sol();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 54ms
memory: 23504kb

input:

486
4 5
..#..
@@O@@
##@#O
..@.@
2 2
OO
OO
2 2
@@
@@
2 2
@@
#@
2 2
@O
#@
2 2
@@
OO
2 2
O#
@O
2 2
@#
#@
2 2
@.
.@
2 2
@#
.O
2 2
OO
.O
10 10
@O@O#O@@@#
OO#@#@@#OO
#@#@#O##O@
OO##@@O#@O
O##@@#@O#@
OO@OO@@@O@
@O#@#@O#@O
@OOOOO@##.
O@OOO##O@@
OO@@OOOO#@
10 10
@@#OOO#O@@
#@@OO@@.O@
#.O@@O#@@O
OO@@#O@#O@
.#...

output:

TAK
NTNN
NNTNT
DPPDDPP
TAK
NN
NN
DP
TAK
NN
TT
DP
TAK
NN
TT
PD
TAK
TN
NT
PD
TAK
TN
NN
DP
TAK
TN
TN
DP
NIE
TAK
TN
NT
DP
TAK
TN
NN
DP
TAK
NN
NN
DP
NIE
TAK
NNTTNNNNTN
TTTNNTNNTT
PDPPDDDDDDPPDDPPPP
TAK
NTTTTNTNNN
NNTNTTNTTN
DDDPPPPDDPPDDDDPPP
TAK
TNTNTNNNTN
TTTNNNNTTN
PPDDPDDDDDDDPPPPPP
TAK
TNNNTNTNTN
TN...

result:

ok ac (486 test cases)

Extra Test:

score: 0
Extra Test Passed