結果
問題 |
No.1508 Avoid being hit
|
ユーザー |
![]() |
提出日時 | 2021-05-14 23:53:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,943 bytes |
コンパイル時間 | 4,002 ms |
コンパイル使用メモリ | 238,344 KB |
実行使用メモリ | 284,928 KB |
最終ジャッジ日時 | 2024-10-02 06:24:16 |
合計ジャッジ時間 | 12,944 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | TLE * 1 -- * 42 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; #define REP(i,a,n) for(int i=(a); i<(int)(n); i++) #define rep(i,n) REP(i,0,n) #define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; //using mint = modint1000000007; //using mint = modint998244353; vector<int> solve(int N, const vector<pair<int,int>>& v){ int Q = v.size(); vector<int> ret; vector<set<int>> dame(Q); dame[Q-1].insert(v[Q-1].first); dame[Q-1].insert(v[Q-1].second); for(int i=Q-2; i>=0; i--){ int a = v[i].first; int b = v[i].second; dame[i].insert(a); dame[i].insert(b); FOR(it,dame[i+1]){ REP(j,-1,2){ int pos = *it + j; if(1<=pos && pos<=N){ bool ok = false; REP(k,-1,2){ int npos = pos + k; if(1<=npos && npos<=N && dame[i+1].find(npos) == dame[i+1].end()){ ok = true; break; } } if(!ok){ dame[i].insert(pos); } } } } } REP(i,1,N+1){ if(dame[0].find(i) == dame[0].end()){ int pos = i; ret.push_back(pos); rep(j,Q-1){ int nxt = pos; REP(k,-1,2){ int npos = pos + k; if(1<=npos && npos<=N && dame[j+1].find(npos) == dame[j+1].end()){ nxt = npos; break; } } pos = nxt; ret.push_back(pos); } break; } } return ret; } int main(){ int N, Q; cin >> N >> Q; vector<pair<int,int>> v(Q); rep(i,Q) cin >> v[i].first; rep(i,Q) cin >> v[i].second; vector<int> ret = solve(N, v); if(ret.size() > 0){ cout << "YES" << endl; cout << ret[0] << endl; rep(i,ret.size()) cout << ret[i] << endl; return 0; } cout << "NO" << endl; return 0; }