QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#100793 | #4432. Jungle Trail | Yanagi_Origami# | AC ✓ | 369ms | 70220kb | C++20 | 3.9kb | 2023-04-28 09:05:57 | 2023-04-28 09:06:00 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <cstring>
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
const int N=2005;
char mp[N][N];
int n,m,k,f[N][N][2][2];
vector<char>ans1,ans2,ans3;
void getans(int x,int y,int u,int v){
if(x==1&&y==1) return ;
//printf("#%d %d %d %d\n",x,y,u,v);
if(f[x][y][u][v]==1){
rep(i,0,1){
if(f[x][y-1][i][v]){
getans(x,y-1,i,v);
ans2.push_back(i?'T':'N');
ans3.push_back('P');
break;
}
}
}else{
rep(i,0,1){
if(f[x-1][y][u][i]){
getans(x-1,y,u,i);
ans1.push_back(i?'T':'N');
ans3.push_back('D');
break;
}
}
}
}
void solve(){
//memset(f,0,sizeof(f));
scanf("%d%d",&n,&m);
rep(i,1,n) rep(j,1,m) rep(_1,0,1) rep(_2,0,1) f[i][j][_1][_2]=0;
ans1.clear(); ans2.clear(); ans3.clear();
rep(i,1,n){
scanf("%s",mp[i]+1);
}
if(mp[1][1]=='.'){
f[1][1][0][0] = 1;
f[1][1][0][1] = 1;
f[1][1][1][0] = 1;
f[1][1][1][1] = 1;
}
if(mp[1][1]=='O'){
f[1][1][0][0] = 1;
f[1][1][1][1] = 1;
}
if(mp[1][1]=='@'){
f[1][1][0][1] = 1;
f[1][1][1][0] = 1;
}
rep(i,1,n){
rep(j,1,m){
if(j<m&&mp[i][j+1]!='#'){//1 => j+1 2=>i+1
if(mp[i][j+1]=='.'){
if(f[i][j][0][0]||f[i][j][1][0])
f[i][j+1][0][0] = 1,
f[i][j+1][1][0] = 1;
if(f[i][j][0][1]||f[i][j][1][1])
f[i][j+1][0][1] = 1,
f[i][j+1][1][1] = 1;
}else{
if(mp[i][j+1]=='O'){
if(f[i][j][0][0]||f[i][j][1][0])
f[i][j+1][0][0] = 1;
if(f[i][j][0][1]||f[i][j][1][1])
f[i][j+1][1][1] = 1;
}else{
if(f[i][j][0][0]||f[i][j][1][0])
f[i][j+1][1][0] = 1;
if(f[i][j][0][1]||f[i][j][1][1])
f[i][j+1][0][1] = 1;
}
}
}
if(i<n&&mp[i+1][j]!='#'){
if(mp[i+1][j]=='.'){
if(f[i][j][0][0]||f[i][j][0][1])
f[i+1][j][0][0] = 2,
f[i+1][j][0][1] = 2;
if(f[i][j][1][0]||f[i][j][1][1])
f[i+1][j][1][0] = 2,
f[i+1][j][1][1] = 2;
}else{
if(mp[i+1][j]=='O'){
if(f[i][j][0][0]||f[i][j][0][1])
f[i+1][j][0][0] = 2;
if(f[i][j][1][0]||f[i][j][1][1])
f[i+1][j][1][1] = 2;
}else{
if(f[i][j][0][0]||f[i][j][0][1])
f[i+1][j][0][1] = 2;
if(f[i][j][1][0]||f[i][j][1][1])
f[i+1][j][1][0] = 2;
}
}
}
}
}
rep(i,0,1) rep(j,0,1) if(f[n][m][i][j]){
puts("TAK");
getans(n,m,i,j);
ans2.push_back(i?'T':'N');
ans1.push_back(j?'T':'N');
for(auto v:ans1) putchar(v); puts("");
for(auto v:ans2) putchar(v); puts("");
for(auto v:ans3) putchar(v); puts("");
return ;
}
puts("NIE");
}
int main(){
int T;
scanf("%d",&T);
while(T--) solve();
return 0;
}
/*
2
4 5
..#..
@@O@@
##@#O
..@.@
4 5
..#..
@@O@@
##@#O
..@.@
*/
詳細信息
Test #1:
score: 100
Accepted
time: 369ms
memory: 70220kb
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 NNTT TTNNN DPPDDPP TAK NN NN DP TAK TT NN DP TAK TT NN PD TAK NT TN PD TAK TN NN DP TAK TN TN DP NIE TAK TT NN DP TAK TN NN DP TAK NN NN DP NIE TAK TTNNTTTTNT NNTTNNTTNN PDDDPPDDDDPPDDPPPP TAK NTTTNTNNNN NTTTNTNTTN DDDDDPDDDPPPPPDPPP TAK TNTNTNNNTN TTNNNNNTTN DDDPPDPDDDDDPPPPPP TAK TNTNTTTNTN TT...
result:
ok ac (486 test cases)
Extra Test:
score: 0
Extra Test Passed