結果

問題 No.1508 Avoid being hit
ユーザー どららどらら
提出日時 2021-05-15 00:11:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,772 bytes
コンパイル時間 4,288 ms
コンパイル使用メモリ 239,292 KB
実行使用メモリ 17,128 KB
最終ジャッジ日時 2023-07-25 12:42:31
合計ジャッジ時間 12,759 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 5 ms
8,096 KB
testcase_02 AC 4 ms
8,264 KB
testcase_03 AC 4 ms
8,096 KB
testcase_04 AC 4 ms
8,116 KB
testcase_05 AC 5 ms
8,168 KB
testcase_06 AC 5 ms
8,412 KB
testcase_07 AC 5 ms
8,116 KB
testcase_08 AC 4 ms
8,112 KB
testcase_09 AC 5 ms
8,412 KB
testcase_10 AC 4 ms
8,176 KB
testcase_11 AC 5 ms
8,116 KB
testcase_12 AC 5 ms
8,104 KB
testcase_13 AC 5 ms
8,156 KB
testcase_14 AC 5 ms
8,116 KB
testcase_15 AC 4 ms
8,112 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 217 ms
17,116 KB
testcase_25 AC 196 ms
16,356 KB
testcase_26 AC 18 ms
8,732 KB
testcase_27 AC 103 ms
12,272 KB
testcase_28 AC 102 ms
12,228 KB
testcase_29 AC 202 ms
16,596 KB
testcase_30 AC 110 ms
12,480 KB
testcase_31 AC 175 ms
15,480 KB
testcase_32 AC 190 ms
16,136 KB
testcase_33 AC 55 ms
10,264 KB
testcase_34 AC 172 ms
15,412 KB
testcase_35 AC 21 ms
8,864 KB
testcase_36 AC 99 ms
12,072 KB
testcase_37 AC 46 ms
9,836 KB
testcase_38 AC 140 ms
14,112 KB
testcase_39 AC 92 ms
11,824 KB
testcase_40 AC 178 ms
15,812 KB
testcase_41 AC 106 ms
12,360 KB
testcase_42 AC 182 ms
15,804 KB
testcase_43 AC 214 ms
17,128 KB
testcase_44 AC 5 ms
8,136 KB
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;

  //vector<set<int>> dame(Q);
  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;
    }
  }

  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;
}
0