結果

問題 No.1508 Avoid being hit
ユーザー HaaHaa
提出日時 2021-05-14 23:52:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,565 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 169,504 KB
実行使用メモリ 7,244 KB
最終ジャッジ日時 2024-04-10 04:51:24
合計ジャッジ時間 6,388 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 40 ms
6,940 KB
testcase_17 AC 23 ms
6,940 KB
testcase_18 AC 21 ms
6,944 KB
testcase_19 AC 34 ms
6,940 KB
testcase_20 AC 54 ms
6,940 KB
testcase_21 AC 36 ms
6,940 KB
testcase_22 AC 44 ms
6,940 KB
testcase_23 AC 49 ms
6,940 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 138 ms
6,944 KB
testcase_35 AC 15 ms
6,944 KB
testcase_36 AC 77 ms
6,944 KB
testcase_37 AC 33 ms
6,940 KB
testcase_38 AC 107 ms
6,940 KB
testcase_39 AC 70 ms
6,940 KB
testcase_40 AC 135 ms
6,940 KB
testcase_41 AC 80 ms
6,940 KB
testcase_42 AC 144 ms
6,940 KB
testcase_43 AC 162 ms
7,244 KB
testcase_44 AC 1 ms
6,940 KB
testcase_45 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(ll i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

int main(){
    int n, q; cin >> n >> q;
    VI a(q), b(q);
    REP(i,q) cin >> a[i], a[i]--;
    REP(i,q) cin >> b[i], b[i]--;
    int l=-1, r=n;
    VI x(q), y(q);
    for(int i=q-1;i>=0;i--){
        if(a[i]>b[i]) swap(a[i],b[i]);
        if(l+1==a[i]&&a[i]+1==b[i])
            l++;
        else if(l==a[i]&&a[i]+1==b[i])
            l+=0;
        else
            l=max(l-1,-1);
        if(r-1==b[i]&&a[i]+1==b[i])
            r--;
        else if(r==b[i]&&a[i]+1==b[i])
            r+=0;
        else
            r=min(r+1,n);
        x[i]=l;
        y[i]=r;
    }
    VI ans;
    int now=x[0]+1;
    ans.push_back(now);
    bool no=0;
    REP(i,q){
        int p=-1;
        for(int j=-1;j<=1;j++){
            bool ok=1;
            if((i<q-1&&(now+j>=y[i+1]||now+j<=x[i+1]))||now+j>=n||now+j<0)
                ok=0;
            if(now+j==a[i])
                ok=0;
            if(now+j==b[i])
                ok=0;
            if(ok){
                p=now+j;
                break;
            }
        }
        now=p;
        if(now==-1){
            no=1;
            break;
        }
        ans.push_back(now);
    }
    if(no){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
        REP(i,q+1){
            cout << ans[i]+1 << endl;
        }
    }
}
0