結果

問題 No.1508 Avoid being hit
ユーザー どららどらら
提出日時 2021-05-16 07:29:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,038 bytes
コンパイル時間 3,978 ms
コンパイル使用メモリ 232,416 KB
実行使用メモリ 25,656 KB
最終ジャッジ日時 2024-04-15 01:13:22
合計ジャッジ時間 9,202 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 157 ms
12,920 KB
testcase_01 AC 4 ms
8,168 KB
testcase_02 AC 4 ms
8,200 KB
testcase_03 AC 4 ms
8,228 KB
testcase_04 AC 4 ms
8,208 KB
testcase_05 AC 4 ms
8,232 KB
testcase_06 AC 4 ms
8,116 KB
testcase_07 AC 3 ms
8,204 KB
testcase_08 AC 3 ms
8,336 KB
testcase_09 AC 4 ms
8,176 KB
testcase_10 AC 4 ms
8,204 KB
testcase_11 AC 4 ms
8,316 KB
testcase_12 AC 3 ms
8,316 KB
testcase_13 AC 4 ms
8,304 KB
testcase_14 AC 4 ms
8,248 KB
testcase_15 AC 4 ms
8,176 KB
testcase_16 AC 45 ms
12,624 KB
testcase_17 AC 29 ms
10,744 KB
testcase_18 AC 26 ms
9,888 KB
testcase_19 AC 40 ms
12,016 KB
testcase_20 AC 62 ms
13,260 KB
testcase_21 AC 43 ms
11,540 KB
testcase_22 AC 50 ms
12,472 KB
testcase_23 AC 57 ms
12,980 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 16 ms
9,004 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 146 ms
13,312 KB
testcase_35 AC 21 ms
9,520 KB
testcase_36 AC 88 ms
13,236 KB
testcase_37 AC 43 ms
10,820 KB
testcase_38 AC 121 ms
15,800 KB
testcase_39 AC 86 ms
15,408 KB
testcase_40 AC 150 ms
16,988 KB
testcase_41 AC 94 ms
14,304 KB
testcase_42 AC 159 ms
17,036 KB
testcase_43 AC 204 ms
25,656 KB
testcase_44 AC 4 ms
8,220 KB
testcase_45 AC 4 ms
8,352 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+1].first <= last){
          k++;
          last = s[k].second;
        }
        else break;
      }
      j = k;
      ok[i].insert(make_pair(s[j].first,last));
    }
  }
  /*
  rep(i,Q){
    cout << i << endl;
    FOR(it,ok[i]){
      cout << "\t" << it->first << " " << it->second << endl;
    }
  }
   */
  
  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