QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189966 | #4432. Jungle Trail | berarchegas# | AC ✓ | 1117ms | 297924kb | C++20 | 4.6kb | 2023-09-28 03:09:37 | 2023-09-28 03:09:37 |
Judging History
answer
#include <bits/stdc++.h>
#include <iostream>
// #define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v)),v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
// std::mt19937_64 rng64((int) std::chrono::steady_clock::now().time_since_epoch().count());
std::mt19937 rng(
// (int) std::chrono::steady_clock::now().time_since_epoch().count()
1239010
);
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
//inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
b%=m;
ll ans = 1;
for (; e; b = b * b % m, e /= 2)
if (e & 1) ans = ans * b % m;
return ans;
}
// debug:
template<class T>void print_vector(vector<T> &v){
rep(i,0,sz(v))cout<<v[i]<<" \n"[i==sz(v)-1];
}
void dbg_out() {cerr << endl; }
template<typename Head, typename ... Tail> void dbg_out(Head H,Tail... T){
cerr << ' ' << H;
dbg_out(T...);
}
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__), cerr << endl
#else
#define dbg(...) 42
#endif
//
const int N = 2050;
string s[N];
bool can[N][N][2][2];
bool vis[N][N][2][2];
struct nx{
int i , j , l , r;
} nxt[N][N][2][2];
int n, m;
bool A[N] , B[N];
bool dp(int i ,int j , int l , int r){
if(i >= n || j >= m)
return 0;
if(s[i][j] == '#')
return 0;
char p = s[i][j];
bool flipped = l ^ r;
if((p == '@' && !flipped) || (p == 'O' && flipped)){
return can[i][j][l][r] = false;
}
if(i == n - 1&& j == m - 1){
can[i][j][l][r] = 1 , nxt[i][j][l][r] = {-1,-1,-1,-1};
return true;
}
if(vis[i][j][l][r])
return can[i][j][l][r];
vis[i][j][l][r] = true;
bool a = dp(i+1,j,0,r);
bool b = dp(i,j+1,l,0);
bool c = dp(i+1,j,1,r);
bool d = dp(i,j+1,l,1);
if(a)
can[i][j][l][r] = 1 , nxt[i][j][l][r] = {i+1,j,0,r};
if(b)
can[i][j][l][r] = 1 , nxt[i][j][l][r] = {i,j+1,l,0};
if(c)
can[i][j][l][r] = 1 , nxt[i][j][l][r] = {i+1,j,1,r};
if(d)
can[i][j][l][r] = 1 , nxt[i][j][l][r] = {i,j+1,l,1};
return can[i][j][l][r];
}
string ans;
void recover(int i , int j , int l , int r){
if(i == -1 )
return;
if(l)
A[i] = true;
if(r)
B[j] = true;
auto [ii, jj , ll, rr] = nxt[i][j][l][r];
if(jj > j)
ans.push_back('P');
else if(ii > i)
ans.push_back('D');
recover(ii, jj , ll, rr);
}
void solve(){
cin >> n >> m;
ans.clear();
for(int i = 0 ; i < n; i ++){
cin >> s[i];
A[i] = 0;
for(int j = 0 ; j < m ; j ++)
for(int l = 0 ; l < 2; l ++)
for(int r = 0 ; r < 2 ; r ++)
can[i][j][l][r] = vis[i][j][l][r] = B[j] = 0;
}
bool pt = dp(0,0,0,0);
bool pt2 = dp(0,0,1,0);
bool pt3 = dp(0,0,0,1);
bool pt4 = dp(0,0,1,1);
if(pt || pt2 || pt3 || pt4){
cout << "TAK" << endl;
if(pt)
recover(0,0,0,0);
else if(pt2)
recover(0,0,1,0);
else if(pt3)
recover(0,0,0,1);
else if(pt4)
recover(0,0,1,1);
for(int i = 0 ; i < n; i ++)
cout << (A[i] ? 'T' : 'N');
cout << endl;
for(int i = 0 ; i < m ; i ++)
cout << (B[i] ? 'T' : 'N');
cout << endl;
cout << ans << endl;
}
else{
cout << "NIE" << endl;
}
}
int32_t main(){
fastio;
int t;
cin >> t;
while(t--){
solve();
}
// math -> gcd it all
// Did you swap N,M? N=1?
}
详细
Test #1:
score: 100
Accepted
time: 1117ms
memory: 297924kb
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 NNTN NTNTT PDPPPDD TAK NN NN PD TAK TT NN DP TAK TT NN PD TAK TN NT PD TAK TN NN PD TAK NT NT DP NIE TAK TN NT PD TAK TT NT DP TAK NT NT DP NIE TAK TTTTNNTTTN NNTNNNNNNT PDDPPDDDPPPDPPPDDD TAK NTTNNNTTTT NTNTNTTTNT DDPPDPPDPDDDPDPPPD TAK NTTTNNNNNT NNTTTTNNTT DPPDDPPPPDPPDDPDDD TAK NTTTNTNTNT NT...
result:
ok ac (486 test cases)
Extra Test:
score: 0
Extra Test Passed