結果
問題 | No.1508 Avoid being hit |
ユーザー | どらら |
提出日時 | 2021-05-16 07:29:07 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,038 bytes |
コンパイル時間 | 3,955 ms |
コンパイル使用メモリ | 238,572 KB |
実行使用メモリ | 25,824 KB |
最終ジャッジ日時 | 2024-10-04 08:16:00 |
合計ジャッジ時間 | 9,503 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 156 ms
12,928 KB |
testcase_01 | AC | 5 ms
8,192 KB |
testcase_02 | AC | 4 ms
8,232 KB |
testcase_03 | AC | 5 ms
8,200 KB |
testcase_04 | AC | 4 ms
8,296 KB |
testcase_05 | AC | 5 ms
8,108 KB |
testcase_06 | AC | 5 ms
8,320 KB |
testcase_07 | AC | 5 ms
8,216 KB |
testcase_08 | AC | 5 ms
8,128 KB |
testcase_09 | AC | 5 ms
8,156 KB |
testcase_10 | AC | 5 ms
8,132 KB |
testcase_11 | AC | 4 ms
8,112 KB |
testcase_12 | AC | 5 ms
8,244 KB |
testcase_13 | AC | 3 ms
8,192 KB |
testcase_14 | AC | 5 ms
8,276 KB |
testcase_15 | AC | 5 ms
8,148 KB |
testcase_16 | AC | 52 ms
12,488 KB |
testcase_17 | AC | 31 ms
10,588 KB |
testcase_18 | AC | 27 ms
10,016 KB |
testcase_19 | AC | 45 ms
12,032 KB |
testcase_20 | AC | 66 ms
13,152 KB |
testcase_21 | AC | 44 ms
11,468 KB |
testcase_22 | AC | 55 ms
12,544 KB |
testcase_23 | AC | 61 ms
12,672 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 16 ms
8,752 KB |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | AC | 145 ms
13,252 KB |
testcase_35 | AC | 20 ms
9,548 KB |
testcase_36 | AC | 90 ms
13,112 KB |
testcase_37 | AC | 44 ms
10,948 KB |
testcase_38 | AC | 129 ms
15,820 KB |
testcase_39 | AC | 91 ms
15,412 KB |
testcase_40 | AC | 161 ms
16,908 KB |
testcase_41 | AC | 98 ms
14,104 KB |
testcase_42 | AC | 163 ms
17,040 KB |
testcase_43 | AC | 211 ms
25,824 KB |
testcase_44 | AC | 4 ms
8,192 KB |
testcase_45 | AC | 4 ms
8,212 KB |
ソースコード
#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>> ok[100005]; vector<int> solve(int N, const vector<pair<int,int>>& v){ int Q = v.size(); vector<int> ret; { int a = v[Q-1].first; int b = v[Q-1].second; if(a > b) swap(a,b); if(a+1 == b){ if(a-1>=1 && 1<=a-1) ok[Q-1].insert(make_pair(1,a-1)); if(b+1<=N && b+1<=N) ok[Q-1].insert(make_pair(b+1,N)); }else{ if(a-1>=1 && 1<=a-1) ok[Q-1].insert(make_pair(1,a-1)); if(a+1<=b-1) ok[Q-1].insert(make_pair(a+1,b-1)); if(b+1<=N && b+1<=N) ok[Q-1].insert(make_pair(b+1,N)); } } for(int i=Q-2; i>=0; i--){ int a = v[i].first; int b = v[i].second; if(a > b) swap(a,b); vector<pair<int,int>> s; FOR(it,ok[i+1]){ int aa = it->first - 1; int bb = it->second + 1; aa = max(aa, 1); bb = min(bb, N); if(aa <= a && a <= bb && aa <= b && b <= bb){ if(a-1>=1 && aa<=a-1) s.emplace_back(aa,a-1); if(a+1<=b-1) s.emplace_back(a+1,b-1); if(b+1<=N && b+1<=bb) s.emplace_back(b+1,bb); } else if(aa <= a && a <= bb){ if(a-1>=1 && aa<=a-1) s.emplace_back(aa,a-1); if(a+1<=N && a+1<=bb) s.emplace_back(a+1,bb); } else if(aa <= b && b <= bb){ if(b-1>=1 && aa<=b-1) s.emplace_back(aa,b-1); if(b+1<=N && b+1<=bb) s.emplace_back(b+1,bb); } else{ s.emplace_back(aa,bb); } } rep(j,s.size()){ int last = s[j].second; int k=j; while(k+1<s.size()){ if(s[k+1].first <= last){ k++; last = s[k].second; } else break; } j = k; ok[i].insert(make_pair(s[j].first,last)); } } /* rep(i,Q){ cout << i << endl; FOR(it,ok[i]){ cout << "\t" << it->first << " " << it->second << endl; } } */ if(ok[0].size() == 0) return vector<int>(); int pos = ok[0].begin()->first; ret.push_back(pos); REP(i,1,Q){ int nxt = pos; REP(j,-1,2){ int npos = pos + j; bool flg = false; if(1<=npos&&npos<=N){ FOR(it,ok[i]){ if(it->first <= npos && npos <= it->second) flg = true; } } if(flg){ nxt = npos; break; } } pos = nxt; ret.push_back(pos); } 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; }