QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202182 | #4432. Jungle Trail | Forever_Young# | AC ✓ | 102ms | 45684kb | C++23 | 1.9kb | 2023-10-05 20:29:35 | 2023-10-05 20:29:35 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n;i>=1;i--)
#define mp make_pair
#define pb push_back
int n,m;
char s[2100][2100];
bool f[2100][2100];
int row[2100],col[2100];
pair<int,int> pre[2100][2100];
int main()
{
int T;
cin>>T;
while (T--)
{
scanf("%d%d",&n,&m);
rep(i,n)scanf("%s",s[i]+1);
rep(i,n)rep(j,m)f[i][j]=0;
if (f[1][1]!='#')f[1][1]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if (i==1 && j==1)
if (f[1][1]!='#')f[1][1]=1;
if (i>1 && f[i-1][j]==1)pre[i][j]=mp(i-1,j),f[i][j]=1;
if (j>1 && f[i][j-1]==1)pre[i][j]=mp(i,j-1),f[i][j]=1;
if (s[i][j]=='#')f[i][j]=0;
}
if (f[n][m]==0)puts("NIE");
else
{
puts("TAK");
static vector<char> ans; ans.clear();
int nowx=n,nowy=m;
while (nowx!=1 || nowy!=1)
{
if (nowx==pre[nowx][nowy].first)ans.pb('P'); else ans.pb('D');
tie(nowx,nowy)=pre[nowx][nowy];
}
reverse(ans.begin(),ans.end());
nowx=1,nowy=1;
for(int i=1;i<=n;i++)row[i]=-1;
for(int i=1;i<=m;i++)col[i]=-1;
if (s[1][1]=='@')row[1]=1;
for(auto p:ans)
{
if (p=='P')nowy++; else nowx++;
int f=0; if (s[nowx][nowy]=='@')f=1;
if (row[nowx]==1)f^=1;
if (col[nowy]==1)f^=1;
if (f)
{
if (p=='D')row[nowx]=1;
else col[nowy]=1;
}
}
for(int i=1;i<=n;i++)if (row[i]==1)putchar('T'); else putchar('N'); puts("");
for(int i=1;i<=m;i++)if (col[i]==1)putchar('T'); else putchar('N'); puts("");
/*
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if (s[i][j]=='.' || s[i][j]=='#'){ putchar(s[i][j]); continue; }
int f; if (s[i][j]=='@')f=1; else f=0;
if (row[i]==1)f^=1;
if (col[j]==1)f^=1;
if (f==1)putchar('@'); else putchar('O');
}
puts("");
}*/
for(auto p:ans)putchar(p); puts("");
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 102ms
memory: 45684kb
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 TT NN DP TAK TT NN PD TAK TN NT PD TAK TN NN DP TAK NT NT DP NIE TAK TN NT DP TAK TN NN DP TAK NN NN DP NIE TAK TTNNTTTTNT NNTTTNTTNN PDDDPPDDDDPPDDPPPP TAK NTTTNTNNNN NTTTNTNTTN DDDDDPDDDPPPPPDPPP TAK NNNTNTTTNT NNTTTTTNNT DDDPPDPDDDDDPPPPPP TAK NNNTNNNTNT NN...
result:
ok ac (486 test cases)
Extra Test:
score: 0
Extra Test Passed