結果
問題 | No.1508 Avoid being hit |
ユーザー |
![]() |
提出日時 | 2021-05-15 00:21:14 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,887 bytes |
コンパイル時間 | 4,236 ms |
コンパイル使用メモリ | 240,212 KB |
実行使用メモリ | 17,280 KB |
最終ジャッジ日時 | 2024-10-02 07:12:45 |
合計ジャッジ時間 | 9,697 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 WA * 1 |
ソースコード
#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;set<pair<int,int>> dame[100005];bool sfind(set<pair<int,int>>& s, int x){FOR(it,s){if(it->first <= x && x <= it->second) return true;}return false;}vector<int> solve(int N, const vector<pair<int,int>>& v){int Q = v.size();vector<int> ret;dame[Q-1].insert(make_pair(v[Q-1].first,v[Q-1].first));dame[Q-1].insert(make_pair(v[Q-1].second,v[Q-1].second));for(int i=Q-2; i>=0; i--){int a = v[i].first;int b = v[i].second;set<int> tmp;tmp.insert(a);tmp.insert(b);FOR(it,dame[i+1]){REP(j,-1,2){int pos = it->first + j;if(1<=pos && pos<=N){bool ok = false;REP(k,-1,2){int npos = pos + k;if(1<=npos && npos<=N && !sfind(dame[i+1], npos)){ok = true;break;}}if(!ok){tmp.insert(pos);}}}REP(j,-1,2){int pos = it->second + j;if(1<=pos && pos<=N){bool ok = false;REP(k,-1,2){int npos = pos + k;if(1<=npos && npos<=N && !sfind(dame[i+1], npos)){ok = true;break;}}if(!ok){tmp.insert(pos);}}}}int bgn = -1;int lst = -1;FOR(it,tmp){if(lst+1 == *it){lst++;}else{if(bgn > 0) dame[i].insert(make_pair(bgn,lst));bgn = *it;lst = *it;}}if(bgn > 0) dame[i].insert(make_pair(bgn,lst));}REP(i,1,N+1){if(!sfind(dame[0], i)){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 && !sfind(dame[j+1], npos)){nxt = npos;break;}}pos = nxt;ret.push_back(pos);}break;}}if(ret.size() > 0){rep(i,Q){int pos = ret[i];if(pos == v[i].first || pos == v[i].second) return vector<int>();}}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;}