結果

問題 No.1508 Avoid being hit
ユーザー どららどらら
提出日時 2021-05-16 07:22:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,897 bytes
コンパイル時間 4,361 ms
コンパイル使用メモリ 232,384 KB
実行使用メモリ 13,324 KB
最終ジャッジ日時 2024-04-15 01:08:48
合計ジャッジ時間 9,740 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
13,012 KB
testcase_01 AC 5 ms
8,444 KB
testcase_02 AC 4 ms
8,244 KB
testcase_03 AC 4 ms
8,112 KB
testcase_04 AC 3 ms
8,204 KB
testcase_05 AC 4 ms
8,096 KB
testcase_06 AC 3 ms
8,336 KB
testcase_07 AC 4 ms
8,188 KB
testcase_08 AC 4 ms
8,296 KB
testcase_09 AC 4 ms
8,476 KB
testcase_10 AC 4 ms
8,232 KB
testcase_11 AC 4 ms
8,320 KB
testcase_12 AC 4 ms
8,404 KB
testcase_13 AC 3 ms
8,448 KB
testcase_14 AC 4 ms
8,448 KB
testcase_15 AC 3 ms
8,204 KB
testcase_16 AC 50 ms
12,644 KB
testcase_17 AC 31 ms
10,624 KB
testcase_18 AC 26 ms
10,008 KB
testcase_19 AC 39 ms
11,992 KB
testcase_20 AC 64 ms
13,280 KB
testcase_21 AC 41 ms
11,508 KB
testcase_22 AC 50 ms
12,524 KB
testcase_23 AC 60 ms
12,664 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 136 ms
12,292 KB
testcase_35 AC 16 ms
8,760 KB
testcase_36 AC 71 ms
10,620 KB
testcase_37 AC 35 ms
9,396 KB
testcase_38 AC 109 ms
11,504 KB
testcase_39 AC 69 ms
10,380 KB
testcase_40 AC 135 ms
12,524 KB
testcase_41 AC 84 ms
10,496 KB
testcase_42 AC 141 ms
12,528 KB
testcase_43 AC 160 ms
13,324 KB
testcase_44 WA -
testcase_45 AC 4 ms
8,140 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>> 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].first <= last){
          k++;
          last = s[k].second;
        }
        else break;
      }
      j = k;
      ok[i].insert(make_pair(s[j].first,last));
    }
  }

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

0