結果

問題 No.1508 Avoid being hit
ユーザー どららどらら
提出日時 2021-05-15 00:18:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,870 bytes
コンパイル時間 4,433 ms
コンパイル使用メモリ 233,584 KB
実行使用メモリ 17,352 KB
最終ジャッジ日時 2024-04-10 05:32:49
合計ジャッジ時間 10,816 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
8,316 KB
testcase_02 RE -
testcase_03 AC 4 ms
8,244 KB
testcase_04 AC 4 ms
8,184 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 5 ms
8,272 KB
testcase_08 AC 4 ms
8,308 KB
testcase_09 AC 4 ms
8,348 KB
testcase_10 RE -
testcase_11 AC 4 ms
8,224 KB
testcase_12 AC 4 ms
8,116 KB
testcase_13 AC 5 ms
8,220 KB
testcase_14 AC 3 ms
8,304 KB
testcase_15 RE -
testcase_16 AC 61 ms
13,188 KB
testcase_17 AC 37 ms
10,940 KB
testcase_18 AC 34 ms
10,384 KB
testcase_19 AC 53 ms
12,556 KB
testcase_20 AC 80 ms
13,788 KB
testcase_21 AC 54 ms
12,000 KB
testcase_22 AC 66 ms
12,964 KB
testcase_23 AC 71 ms
13,468 KB
testcase_24 AC 197 ms
17,352 KB
testcase_25 AC 179 ms
16,508 KB
testcase_26 AC 16 ms
8,844 KB
testcase_27 AC 95 ms
12,448 KB
testcase_28 AC 95 ms
12,508 KB
testcase_29 AC 185 ms
16,628 KB
testcase_30 AC 103 ms
12,628 KB
testcase_31 AC 163 ms
15,708 KB
testcase_32 AC 176 ms
16,392 KB
testcase_33 AC 51 ms
10,492 KB
testcase_34 AC 161 ms
15,596 KB
testcase_35 AC 20 ms
9,036 KB
testcase_36 AC 93 ms
12,240 KB
testcase_37 AC 43 ms
10,076 KB
testcase_38 AC 131 ms
14,188 KB
testcase_39 AC 86 ms
12,068 KB
testcase_40 AC 168 ms
15,924 KB
testcase_41 AC 97 ms
12,532 KB
testcase_42 AC 169 ms
16,140 KB
testcase_43 AC 198 ms
17,308 KB
testcase_44 AC 4 ms
8,268 KB
testcase_45 AC 4 ms
8,256 KB
権限があれば一括ダウンロードができます

ソースコード

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;

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

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

0