結果

問題 No.1508 Avoid being hit
ユーザー tokusakuraitokusakurai
提出日時 2021-05-14 22:44:15
言語 C++17
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 21 ms / 3,000 ms
コード長 1,976 bytes
コンパイル時間 1,637 ms
使用メモリ 4,928 KB
最終ジャッジ日時 2022-11-26 01:00:53
合計ジャッジ時間 4,947 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 19 ms
4,556 KB
testcase_01 AC 1 ms
3,444 KB
testcase_02 AC 1 ms
3,556 KB
testcase_03 AC 1 ms
3,532 KB
testcase_04 AC 1 ms
3,420 KB
testcase_05 AC 2 ms
3,384 KB
testcase_06 AC 2 ms
3,520 KB
testcase_07 AC 1 ms
3,532 KB
testcase_08 AC 2 ms
3,524 KB
testcase_09 AC 1 ms
3,536 KB
testcase_10 AC 1 ms
3,520 KB
testcase_11 AC 1 ms
3,388 KB
testcase_12 AC 1 ms
3,432 KB
testcase_13 AC 1 ms
3,532 KB
testcase_14 AC 2 ms
3,580 KB
testcase_15 AC 2 ms
3,420 KB
testcase_16 AC 13 ms
4,496 KB
testcase_17 AC 7 ms
3,836 KB
testcase_18 AC 7 ms
3,736 KB
testcase_19 AC 11 ms
4,036 KB
testcase_20 AC 16 ms
4,628 KB
testcase_21 AC 11 ms
4,120 KB
testcase_22 AC 13 ms
4,284 KB
testcase_23 AC 14 ms
4,360 KB
testcase_24 AC 21 ms
4,912 KB
testcase_25 AC 19 ms
4,924 KB
testcase_26 AC 2 ms
3,624 KB
testcase_27 AC 10 ms
4,012 KB
testcase_28 AC 10 ms
3,932 KB
testcase_29 AC 19 ms
4,928 KB
testcase_30 AC 11 ms
4,100 KB
testcase_31 AC 17 ms
4,756 KB
testcase_32 AC 19 ms
4,628 KB
testcase_33 AC 5 ms
3,716 KB
testcase_34 AC 17 ms
4,384 KB
testcase_35 AC 3 ms
3,664 KB
testcase_36 AC 10 ms
3,936 KB
testcase_37 AC 6 ms
3,624 KB
testcase_38 AC 14 ms
4,044 KB
testcase_39 AC 10 ms
3,968 KB
testcase_40 AC 17 ms
4,408 KB
testcase_41 AC 11 ms
3,960 KB
testcase_42 AC 18 ms
4,728 KB
testcase_43 AC 20 ms
4,552 KB
testcase_44 AC 2 ms
3,424 KB
testcase_45 AC 1 ms
3,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

int main(){
    int N, Q; cin >> N >> Q;

    vector<int> A(Q), B(Q);
    rep(i, Q) {cin >> A[i]; A[i]--;}
    rep(i, Q) {cin >> B[i]; B[i]--;}

    rep(i, Q){
        if(A[i] > B[i]) swap(A[i], B[i]);
    }

    vector<int> L(Q+1), R(Q+1);
    L[0] = 0, R[0] = N; //[L,R)

    rep(i, Q){
        L[i+1] = L[i]-1, R[i+1] = R[i]+1;

        while(L[i+1] < 0 || L[i+1] == A[i] || L[i+1] == B[i]){
            L[i+1]++;
            if(L[i+1] == N) break;
        }
        while(R[i+1] > N || R[i+1]-1 == A[i] || R[i+1]-1 == B[i]){
            R[i+1]--;
            if(R[i+1] == 0) break;
        }

        if(L[i+1] >= R[i+1]) {cout << "NO\n"; return 0;}
    }

    vector<int> ans(Q+1);
    ans[Q] = L[Q];

    rep3(i, Q-1, 0){
        rep2(j, ans[i+1]-1, ans[i+1]+1){
            if(j < 0 || j >= N) continue;
            if(i > 0 && j == A[i-1] || j == B[i-1]) continue;
            if(L[i] <= j && j < R[i]) ans[i] = j;
        }
    }

    cout << "YES\n";
    rep(i, Q+1){
        cout << ans[i]+1 << '\n';
    }
}
0