QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189961 | #4432. Jungle Trail | berarchegas# | WA | 633ms | 298092kb | C++20 | 4.5kb | 2023-09-28 02:58:07 | 2023-09-28 02:58:08 |
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;
if(vis[i][j][l][r])
return can[i][j][l][r];
vis[i][j][l][r] = true;
char p = s[i][j];
bool flipped = l ^ r;
if((p == '@' && !flipped) || (p == 'O' && flipped)){
if(!l){
bool ff = dp(i,j,1,r);
can[i][j][l][r] |= ff;
if(ff)
nxt[i][j][l][r] = {i,j,1,r};
}
if(!r){
bool ff = dp(i,j,l,1);
can[i][j][l][r] |= ff;
if(ff)
nxt[i][j][l][r] = {i,j,l,1};
}
}
else{
bool a = dp(i+1,j,0,r);
bool b = dp(i,j+1,l,0);
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(i == n - 1&& j == m - 1 && ((p == '@' && flipped) || (p== 'O' && !flipped))){
can[i][j][l][r] = 1 , nxt[i][j][l][r] = {-1,-1,-1,-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);
if(pt){
cout << "TAK" << endl;
recover(0,0,0,0);
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: 0
Wrong Answer
time: 633ms
memory: 298092kb
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 NN TT PD TAK NN TT PD TAK NN TT PD TAK NT TT PD TAK NN TN DP NIE TAK NN TT PD TAK NN TN DP TAK NN NN PD NIE TAK NNNTTNNNNN TTTNNTTNTT PDPPPPPPPDDDDDPDDD TAK NNNTTNNNNN NNTNTTNTTN PPDDDPPDPDPPDDPDPD TAK NNNNTNNNNT NNNTTNTTTT PPDDPPPDPDPPDDPDDD TAK NNNNTNTNNT NT...
result:
wrong answer you dead (test case 5)