QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202170#4432. Jungle TrailForever_Young#WA 106ms45940kbC++231.9kb2023-10-05 20:25:342023-10-05 20:25:34

Judging History

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

  • [2023-10-05 20:25:34]
  • 评测
  • 测评结果:WA
  • 用时:106ms
  • 内存:45940kb
  • [2023-10-05 20:25:34]
  • 提交

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 (i>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; 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: 0
Wrong Answer
time: 106ms
memory: 45940kb

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
NT
NN
DP
TAK
TT
NN
DP
NIE
NIE
TAK
TN
NN
DP
TAK
NT
NN
DP
NIE
TAK
TN
NT
DP
TAK
TT
NN
DP
TAK
NN
NN
DP
NIE
NIE
TAK
NTTTTTTTTN
NNNNTNTTTT
DDDDDPDDDPPPPPDPPP
TAK
NTTTNNTNNT
NNTTNTNNNT
DDDPPDPDDDDDPPPPPP
TAK
NTTTNNNTTN
NNNNNNTNNN
DDDPPDDPDPDPPPDPPD
NIE
TAK
TTTTTTTTTT
NNNNNTNNNN
D...

result:

wrong answer you dead (test case 2)