結果

問題 No.1508 Avoid being hit
ユーザー chocoruskchocorusk
提出日時 2021-05-15 00:08:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 551 ms / 3,000 ms
コード長 2,671 bytes
コンパイル時間 3,870 ms
コンパイル使用メモリ 194,708 KB
実行使用メモリ 155,820 KB
最終ジャッジ日時 2024-04-10 05:38:36
合計ジャッジ時間 13,084 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 551 ms
155,820 KB
testcase_01 AC 5 ms
8,376 KB
testcase_02 AC 5 ms
8,212 KB
testcase_03 AC 5 ms
8,348 KB
testcase_04 AC 5 ms
8,304 KB
testcase_05 AC 4 ms
8,260 KB
testcase_06 AC 4 ms
8,136 KB
testcase_07 AC 4 ms
8,436 KB
testcase_08 AC 4 ms
8,304 KB
testcase_09 AC 5 ms
8,112 KB
testcase_10 AC 4 ms
8,300 KB
testcase_11 AC 4 ms
8,348 KB
testcase_12 AC 4 ms
8,292 KB
testcase_13 AC 3 ms
8,280 KB
testcase_14 AC 3 ms
8,244 KB
testcase_15 AC 5 ms
8,288 KB
testcase_16 AC 326 ms
54,328 KB
testcase_17 AC 173 ms
33,052 KB
testcase_18 AC 219 ms
40,572 KB
testcase_19 AC 252 ms
42,944 KB
testcase_20 AC 550 ms
86,772 KB
testcase_21 AC 336 ms
57,512 KB
testcase_22 AC 424 ms
68,928 KB
testcase_23 AC 502 ms
78,804 KB
testcase_24 AC 258 ms
45,984 KB
testcase_25 AC 235 ms
42,868 KB
testcase_26 AC 20 ms
10,508 KB
testcase_27 AC 122 ms
25,624 KB
testcase_28 AC 121 ms
25,876 KB
testcase_29 AC 239 ms
43,604 KB
testcase_30 AC 130 ms
27,044 KB
testcase_31 AC 211 ms
39,084 KB
testcase_32 AC 227 ms
41,676 KB
testcase_33 AC 64 ms
17,404 KB
testcase_34 AC 142 ms
9,096 KB
testcase_35 AC 19 ms
8,448 KB
testcase_36 AC 82 ms
8,792 KB
testcase_37 AC 38 ms
8,612 KB
testcase_38 AC 114 ms
8,924 KB
testcase_39 AC 75 ms
8,768 KB
testcase_40 AC 147 ms
9,296 KB
testcase_41 AC 86 ms
8,692 KB
testcase_42 AC 149 ms
9,176 KB
testcase_43 AC 172 ms
9,184 KB
testcase_44 AC 4 ms
8,428 KB
testcase_45 AC 4 ms
8,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
map<int, int> pr[100010];
int main()
{
    int n, q; cin>>n>>q;
	int a[100010], b[100010];
	for(int i=0; i<q; i++){
		cin>>a[i]; a[i]--;
	}
	for(int i=0; i<q; i++){
		cin>>b[i]; b[i]--;
	}
    for(int i=-20; i<=20; i++){
        int x=a[0]+i;
        if(x>=0 && x<n) pr[0][x]=0;
    }
    for(int i=0; i<q; i++){
        for(auto p:pr[i]){
            int x=p.first;
            for(int k=-1; k<=1; k++){
                int y=x+k;
                if(y<0 || y>=n) continue;
                int d1=abs(y-a[i]), d2=abs(y-b[i]);
                if(d1>0 && d2>0 && (d1<=20 || d2<=20)){
                    pr[i+1][y]=x;
                }
            }
        }
    }
    if(pr[q].empty()){
        mt19937 mt(334);
        uniform_int_distribution rndn(0, n-1);
        {
            for(int l=0; l<50; l++){
                int s=rndn(mt);
                vector<int> ans;
                bool dame=0;
                ans.push_back(s+1);
                for(int i=0; i<q; i++){
                    vector<int> v;
                    if(s-1>=0 && a[i]!=s-1 && b[i]!=s-1){
                        v.push_back(s-1);
                    }
                    if(a[i]!=s && b[i]!=s){
                        v.push_back(s);
                    }
                    if(s+1<n && a[i]!=s+1 && b[i]!=s+1){
                        v.push_back(s+1);
                    }
                    if(v.empty()){
                        dame=1;break;
                    }
                    s=v[mt()%((int)v.size())];
                    ans.push_back(s+1);
                }
                if(!dame){
                    cout<<"YES"<<endl;
                    for(auto x:ans) cout<<x<<endl;
                    return 0;
                }
            }
            cout<<"NO"<<endl;
            return 0;
        }
        return 0;
    }
    cout<<"YES"<<endl;
    int x=pr[q].begin()->first;
    vector<int> ans;
    for(int i=q; i>=0; i--){
        ans.push_back(x);
        x=pr[i][x];
    }
    reverse(ans.begin(), ans.end());
    for(auto y:ans) cout<<y+1<<endl;
    return 0;
}
0