結果
問題 | No.1508 Avoid being hit |
ユーザー | どらら |
提出日時 | 2021-05-16 08:01:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 194 ms / 3,000 ms |
コード長 | 3,154 bytes |
コンパイル時間 | 3,709 ms |
コンパイル使用メモリ | 237,888 KB |
実行使用メモリ | 25,372 KB |
最終ジャッジ日時 | 2024-10-04 09:05:45 |
合計ジャッジ時間 | 8,732 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 149 ms
14,128 KB |
testcase_01 | AC | 4 ms
8,104 KB |
testcase_02 | AC | 3 ms
8,128 KB |
testcase_03 | AC | 4 ms
8,200 KB |
testcase_04 | AC | 3 ms
8,232 KB |
testcase_05 | AC | 3 ms
8,112 KB |
testcase_06 | AC | 3 ms
8,236 KB |
testcase_07 | AC | 4 ms
8,148 KB |
testcase_08 | AC | 3 ms
8,128 KB |
testcase_09 | AC | 4 ms
8,112 KB |
testcase_10 | AC | 3 ms
8,188 KB |
testcase_11 | AC | 3 ms
8,152 KB |
testcase_12 | AC | 3 ms
8,144 KB |
testcase_13 | AC | 3 ms
8,128 KB |
testcase_14 | AC | 3 ms
8,128 KB |
testcase_15 | AC | 3 ms
8,108 KB |
testcase_16 | AC | 53 ms
13,864 KB |
testcase_17 | AC | 31 ms
11,352 KB |
testcase_18 | AC | 29 ms
10,576 KB |
testcase_19 | AC | 45 ms
13,012 KB |
testcase_20 | AC | 68 ms
14,704 KB |
testcase_21 | AC | 46 ms
12,476 KB |
testcase_22 | AC | 57 ms
13,592 KB |
testcase_23 | AC | 62 ms
14,108 KB |
testcase_24 | AC | 185 ms
23,420 KB |
testcase_25 | AC | 174 ms
22,284 KB |
testcase_26 | AC | 15 ms
9,140 KB |
testcase_27 | AC | 88 ms
15,256 KB |
testcase_28 | AC | 91 ms
15,368 KB |
testcase_29 | AC | 184 ms
22,420 KB |
testcase_30 | AC | 103 ms
15,800 KB |
testcase_31 | AC | 158 ms
20,792 KB |
testcase_32 | AC | 179 ms
21,804 KB |
testcase_33 | AC | 47 ms
11,756 KB |
testcase_34 | AC | 154 ms
22,252 KB |
testcase_35 | AC | 18 ms
9,612 KB |
testcase_36 | AC | 89 ms
15,980 KB |
testcase_37 | AC | 41 ms
11,672 KB |
testcase_38 | AC | 126 ms
19,252 KB |
testcase_39 | AC | 86 ms
15,340 KB |
testcase_40 | AC | 169 ms
22,648 KB |
testcase_41 | AC | 95 ms
16,448 KB |
testcase_42 | AC | 174 ms
23,012 KB |
testcase_43 | AC | 194 ms
25,372 KB |
testcase_44 | AC | 3 ms
8,180 KB |
testcase_45 | AC | 3 ms
8,220 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; class Range { public: struct RNG { ll l, r; bool operator<(const RNG& a) const { return r < a.r; } }; set<RNG> rngs; void add(ll nl, ll nr){ RNG rng; rng.l = nl; rng.r = nr; auto bgn = rngs.lower_bound((RNG){nl-1,nl-1}); auto it = bgn; for(; it != rngs.end(); it++){ if(it->l <= rng.r+1){ nl = min(nl, it->l); nr = max(nr, it->r); }else{ break; } } rngs.erase(bgn, it); rngs.insert((RNG){nl,nr}); } void erase(ll nl, ll nr){ RNG rng; rng.l = nl; rng.r = nr; set<RNG> tmp; auto bgn = rngs.lower_bound((RNG){nl-1,nl-1}); auto it = bgn; for(; it != rngs.end(); it++){ if(it->l <= rng.r){ if(it->l < nl){ tmp.insert((RNG){it->l,nl-1}); } if(nr < it->r){ tmp.insert((RNG){nr+1,it->r}); } }else{ break; } } rngs.erase(bgn, it); FOR(it,tmp){ rngs.insert(*it); } } }; Range 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].add(1,a-1); if(b+1<=N && b+1<=N) ok[Q-1].add(b+1,N); }else{ if(a-1>=1 && 1<=a-1) ok[Q-1].add(1,a-1); if(a+1<=b-1) ok[Q-1].add(a+1,b-1); if(b+1<=N && b+1<=N) ok[Q-1].add(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); FOR(it,ok[i+1].rngs){ int aa = it->l - 1; int bb = it->r + 1; aa = max(aa, 1); bb = min(bb, N); ok[i].add(aa,bb); } ok[i].erase(a,a); ok[i].erase(b,b); } /* rep(i,Q){ cout << i << endl; FOR(it,ok[i]){ cout << "\t" << it->first << " " << it->second << endl; } } */ if(ok[0].rngs.size() == 0) return vector<int>(); int pos = ok[0].rngs.begin()->l; 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].rngs){ if(it->l <= npos && npos <= it->r) 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; }