QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#553997 | #4432. Jungle Trail | wisniewskij | AC ✓ | 279ms | 20276kb | C++20 | 3.2kb | 2024-09-09 01:17:31 | 2024-09-09 01:17:31 |
Judging History
answer
#include <bits/stdc++.h>
#define ndl '\n'
#define ll long long
#define INF 1000000007
#define st first
#define nd second
#define debug(x) cout << #x << ": " << x << ndl
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
using namespace std;
enum class Field {
Blocked,
Open,
Trap,
Defused_trap
};
enum class Path {
Right,
Down
};
void rob() {
int n, m; cin>>n>>m;
vector<vector<Field>> t(n, vector<Field>(m, Field::Open));
for(int i=0;i<n;i++)
for(int j=0;j<m;j++) {
char c; cin>>c;
switch (c)
{
case '.':
t[i][j] = Field::Open;
break;
case '#':
t[i][j] = Field::Blocked;
break;
case 'O':
t[i][j] = Field::Defused_trap;
break;
case '@':
t[i][j] = Field::Trap;
break;
default:
assert(false&&"Input switch");
break;
}
}
vector<Path> path;
vector<vector<bool>> vis(n, vector<bool>(m, 0));
function<bool(int, int)> solve = [&](int row, int col) {
if(row == 0 && col == 0)
return true;
if(row < 0 || col < 0 || vis[row][col] || t[row][col] == Field::Blocked)
return false;
vis[row][col] = true;
if(solve(row-1, col)) {
path.push_back(Path::Down);
return true;
}
if(solve(row, col-1)) {
path.push_back(Path::Right);
return true;
}
return false;
};
if(!solve(n-1, m-1)) {
cout<<"NIE\n";
return;
}
cout<<"TAK\n";
vector<bool> rows(n), cols(m);
function<void(int, int)> reverse_row = [&](int row, int col) {
if(t[row][col] == Field::Trap && !(rows[row] ^ cols[col])) {
rows[row] = !rows[row];
} else if (t[row][col] == Field::Defused_trap && (rows[row] ^ cols[col])) {
rows[row] = !rows[row];
}
};
function<void(int, int)> reverse_col = [&](int row, int col) {
if(t[row][col] == Field::Trap && !(rows[row] ^ cols[col])) {
cols[col] = !cols[col];
} else if (t[row][col] == Field::Defused_trap && (rows[row] ^ cols[col])) {
cols[col] = !cols[col];
}
};
int row = 0, col = 0;
reverse_col(row, col);
for(auto x:path) {
if(x == Path::Down) {
row++;
reverse_row(row, col);
} else {
col++;
reverse_col(row, col);
}
}
for(auto x:rows) {
cout<<(x?'T':'N');
}
cout<<'\n';
for(auto x:cols) {
cout<<(x?'T':'N');
}
cout<<'\n';
for(auto x:path) {
if(x==Path::Down) cout<<"D";
else cout<<"P";
}
cout<<'\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t;
cin>>t;
for(int i=0;i<t;i++)
rob();
}
詳細信息
Test #1:
score: 100
Accepted
time: 279ms
memory: 20276kb
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 NTNT NNTNN PDPPPDD TAK NN NN PD TAK NN TT PD TAK NN TT PD TAK NT TN PD TAK NT TT PD TAK NT NT DP NIE TAK NT TN PD TAK NN TN DP TAK NN NN PD NIE TAK NNTNNTTTTN TTTNNTTNNT PDPPPPPPPDDDDDPDDD TAK NNNTTTNTNN NNTNTNTNTN PPDDDPPDPDPPDDPDPD TAK NNNNTTTTTN NNNTTNTTNN PPDDPPPDPDPPDDPDDD TAK NTTTNNNTNT NT...
result:
ok ac (486 test cases)
Extra Test:
score: 0
Extra Test Passed