結果

問題 No.1508 Avoid being hit
ユーザー どららどらら
提出日時 2021-05-15 00:21:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,887 bytes
コンパイル時間 3,757 ms
コンパイル使用メモリ 234,468 KB
実行使用メモリ 17,320 KB
最終ジャッジ日時 2024-04-10 05:37:45
合計ジャッジ時間 8,868 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 4 ms
8,120 KB
testcase_02 AC 4 ms
8,232 KB
testcase_03 AC 4 ms
8,244 KB
testcase_04 AC 5 ms
8,320 KB
testcase_05 AC 4 ms
8,440 KB
testcase_06 AC 3 ms
8,320 KB
testcase_07 AC 3 ms
8,196 KB
testcase_08 AC 4 ms
8,104 KB
testcase_09 AC 4 ms
8,448 KB
testcase_10 AC 3 ms
8,232 KB
testcase_11 AC 3 ms
8,176 KB
testcase_12 AC 4 ms
8,320 KB
testcase_13 AC 4 ms
8,328 KB
testcase_14 AC 4 ms
8,196 KB
testcase_15 AC 4 ms
8,440 KB
testcase_16 AC 60 ms
13,224 KB
testcase_17 AC 35 ms
11,008 KB
testcase_18 AC 31 ms
10,200 KB
testcase_19 AC 48 ms
12,772 KB
testcase_20 AC 75 ms
13,952 KB
testcase_21 AC 50 ms
11,904 KB
testcase_22 AC 60 ms
13,056 KB
testcase_23 AC 68 ms
13,568 KB
testcase_24 AC 185 ms
17,228 KB
testcase_25 AC 172 ms
16,512 KB
testcase_26 AC 16 ms
8,960 KB
testcase_27 AC 87 ms
12,264 KB
testcase_28 AC 86 ms
12,316 KB
testcase_29 AC 173 ms
16,724 KB
testcase_30 AC 94 ms
12,672 KB
testcase_31 AC 153 ms
15,744 KB
testcase_32 AC 170 ms
16,256 KB
testcase_33 AC 47 ms
10,240 KB
testcase_34 AC 151 ms
15,624 KB
testcase_35 AC 18 ms
8,960 KB
testcase_36 AC 87 ms
12,188 KB
testcase_37 AC 41 ms
10,076 KB
testcase_38 AC 122 ms
13,936 KB
testcase_39 AC 80 ms
12,024 KB
testcase_40 AC 169 ms
15,872 KB
testcase_41 AC 94 ms
12,544 KB
testcase_42 AC 162 ms
16,092 KB
testcase_43 AC 188 ms
17,320 KB
testcase_44 AC 3 ms
8,140 KB
testcase_45 AC 4 ms
8,400 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;
    }
  }

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