QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#64426 | #4432. Jungle Trail | Sa3tElSefr# | AC ✓ | 834ms | 132888kb | C++23 | 5.0kb | 2022-11-24 20:02:12 | 2022-11-24 20:02:15 |
Judging History
answer
/// Brrrr Brrrr
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k): returns the number of elements in the set strictly less than k
// find_by_order(k): returns an iterator to the k-th element (zero-based) in the set
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for(int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x,y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 5e5+5, LG = 18, MOD = (119 << 23) + 1;
const long double PI = acos(-1);
const long double EPS = 1e-7;
const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};
int dp[2005][2005][2][2];
int n, m;
char grid[2005][2005];
int solve(int x, int y, bool r, bool c) {
if(x == n - 1 && y == m - 1)
return 1;
int &ret = dp[x][y][r][c];
if(~ret)
return ret;
ret = 0;
if(x + 1 < n) { ///move row
if(grid[x+1][y] == '.') {
ret |= solve(x + 1, y, 0, c) | solve(x + 1, y, 1, c);
} else if(grid[x+1][y] == '#'){}
else if(grid[x+1][y] == 'O')ret |= solve(x + 1, y, c, c);
else if(grid[x+1][y] == '@')ret |= solve(x + 1, y, c ^ 1, c);
}
if(y + 1 < m) { ///move column
if(grid[x][y+1] == '.') {
ret |= solve(x, y + 1, r, 0) | solve(x, y + 1, r, 1);
} else if(grid[x][y + 1] == '#'){}
else if(grid[x][y + 1] == 'O')ret |= solve(x, y + 1, r, r);
else if(grid[x][y + 1] == '@')ret |= solve(x, y + 1, r, r ^ 1);
}
return ret;
}
string ansC, ansR, ansD;
void trace(int x, int y, bool r, bool c) {
if(r)ansR[x] = 'T';
if(c)ansC[y] = 'T';
if(x==n-1&&y==m-1)
return;
if(x + 1 < n) { ///move row
if(grid[x+1][y] == '.') {
if(solve(x + 1, y, 0, c)) {
ansD.push_back('D');
trace(x + 1, y, 0, c);
return;
}
if(solve(x + 1, y, 1, c)) {
ansD.push_back('D');
trace(x + 1, y, 1, c);
return;
}
} else if(grid[x+1][y] == '#'){}
else if(grid[x+1][y] == 'O'){
if(solve(x + 1, y, c, c)) {
ansD.push_back('D');
trace(x + 1, y, c, c);
return;
}
}
else if(grid[x+1][y] == '@') {
if(solve(x + 1, y, c ^ 1, c)) {
ansD.push_back('D');
trace(x + 1, y, c ^ 1, c);
return;
}
}
}
if(y + 1 < m) { ///move column
if(grid[x][y+1] == '.') {
if(solve(x, y + 1, r, 0)) {
ansD.push_back('P');
trace(x, y + 1, r, 0);
return;
}
if(solve(x, y + 1, r, 1)) {
ansD.push_back('P');
trace(x, y + 1, r, 1);
return;
}
} else if(grid[x][y+1] == '#'){}
else if(grid[x][y+1] == 'O'){
if(solve(x, y + 1, r, r)) {
ansD.push_back('P');
trace(x, y + 1, r, r);
return;
}
}
else if(grid[x][y + 1] == '@') {
if(solve(x, y + 1, r, r ^ 1)) {
ansD.push_back('P');
trace(x, y + 1, r, r ^ 1);
return;
}
}
}
}
void doWork() {
cin >> n >> m;
f(i,0,n) {
f(j,0,m) {
cin >> grid[i][j];
}
}
f(i,0,n)
f(j,0,m)
memset(dp[i][j], -1, sizeof dp[i][j]);
ansC = string(m,'N');
ansR = string(n,'N');
ansD.clear();
if(solve(0,0,0,0) && (grid[0][0] == '.' || grid[0][0] == 'O')) {
trace(0,0,0,0);
} else if(solve(0,0,1,0) && (grid[0][0] == '.' || grid[0][0] == '@')) {
trace(0,0,1,0);
} else if(solve(0,0,1,1) && (grid[0][0] == '.' || grid[0][0] == 'O')) {
trace(0,0,1,1);
} else if(solve(0,0,0,1) && (grid[0][0] == '.' || grid[0][0] == '@')) {
trace(0,0,0,1);
} else {
cout << "NIE\n";
return;
}
cout << "TAK\n";
cout << ansR << '\n';
cout << ansC << '\n';
cout << ansD << '\n';
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
int t = 1;
cin >> t;
while (t--) {
doWork();
}
return 0;
}
///Look at my code ya codeomk
詳細信息
Test #1:
score: 100
Accepted
time: 834ms
memory: 132888kb
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 NNTTNNTTNN 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