結果

問題 No.1055 牛歩
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2019-09-29 02:10:35
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 1,000 ms
コード長 2,689 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 81,848 KB
実行使用メモリ 29,416 KB
最終ジャッジ日時 2023-10-22 08:01:00
合計ジャッジ時間 5,310 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
29,416 KB
testcase_01 AC 97 ms
28,904 KB
testcase_02 AC 64 ms
22,780 KB
testcase_03 AC 64 ms
22,780 KB
testcase_04 AC 64 ms
22,780 KB
testcase_05 AC 64 ms
22,780 KB
testcase_06 AC 68 ms
22,984 KB
testcase_07 AC 59 ms
21,796 KB
testcase_08 AC 68 ms
22,984 KB
testcase_09 AC 57 ms
22,220 KB
testcase_10 AC 56 ms
22,216 KB
testcase_11 AC 57 ms
22,216 KB
testcase_12 AC 49 ms
20,404 KB
testcase_13 AC 49 ms
20,404 KB
testcase_14 AC 55 ms
22,256 KB
testcase_15 AC 55 ms
22,256 KB
testcase_16 AC 47 ms
21,384 KB
testcase_17 AC 50 ms
21,752 KB
testcase_18 AC 50 ms
21,752 KB
testcase_19 AC 51 ms
21,752 KB
testcase_20 AC 61 ms
22,324 KB
testcase_21 AC 66 ms
22,812 KB
testcase_22 AC 72 ms
23,168 KB
testcase_23 AC 71 ms
23,176 KB
testcase_24 AC 72 ms
23,184 KB
testcase_25 AC 52 ms
22,336 KB
testcase_26 AC 53 ms
22,336 KB
testcase_27 AC 52 ms
22,336 KB
testcase_28 AC 55 ms
22,344 KB
testcase_29 AC 55 ms
22,340 KB
testcase_30 AC 52 ms
22,336 KB
testcase_31 AC 18 ms
19,448 KB
testcase_32 AC 17 ms
19,256 KB
testcase_33 AC 18 ms
19,472 KB
testcase_34 AC 16 ms
19,180 KB
testcase_35 AC 18 ms
19,468 KB
testcase_36 AC 18 ms
19,468 KB
testcase_37 AC 16 ms
19,204 KB
testcase_38 AC 16 ms
19,312 KB
testcase_39 AC 8 ms
18,800 KB
testcase_40 AC 8 ms
18,888 KB
testcase_41 AC 8 ms
18,812 KB
testcase_42 AC 8 ms
18,848 KB
testcase_43 AC 9 ms
18,804 KB
testcase_44 AC 9 ms
18,872 KB
testcase_45 AC 9 ms
18,888 KB
testcase_46 AC 8 ms
18,804 KB
testcase_47 AC 9 ms
18,888 KB
testcase_48 AC 7 ms
18,744 KB
testcase_49 AC 7 ms
18,748 KB
testcase_50 AC 7 ms
18,744 KB
testcase_51 AC 7 ms
18,748 KB
testcase_52 AC 7 ms
18,748 KB
testcase_53 AC 8 ms
18,768 KB
testcase_54 AC 8 ms
18,768 KB
testcase_55 AC 7 ms
18,768 KB
testcase_56 AC 8 ms
18,768 KB
testcase_57 AC 7 ms
18,764 KB
testcase_58 AC 8 ms
18,768 KB
testcase_59 AC 8 ms
18,776 KB
testcase_60 AC 7 ms
18,776 KB
testcase_61 AC 7 ms
18,760 KB
testcase_62 AC 7 ms
18,756 KB
testcase_63 AC 8 ms
18,760 KB
testcase_64 AC 8 ms
18,776 KB
testcase_65 AC 8 ms
18,760 KB
testcase_66 AC 8 ms
18,748 KB
testcase_67 AC 7 ms
18,748 KB
testcase_68 AC 7 ms
18,748 KB
testcase_69 AC 7 ms
18,748 KB
testcase_70 AC 7 ms
18,748 KB
testcase_71 AC 7 ms
18,748 KB
testcase_72 AC 7 ms
18,748 KB
testcase_73 AC 7 ms
18,748 KB
testcase_74 AC 7 ms
18,748 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<vector>
#include<cassert>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

#define DEBUG 0

#define M 214514
int n,m,q;
int a[M],b[M];
vi tu[M];
vi mv[M];
vi lo[M];

void stop(void){
  cout<<"NO"<<endl;
  exit(0);
}

void solve(vi &a,const vi&con){
  int fst=a[0];
  int len=con.size();
  vi uu=con;
  rep(i,len-1)uu[i+1]=max(uu[i+1],uu[i]-1);
  for(int i=len-2;i>=0;i--)uu[i]=max(uu[i],uu[i+1]-1);
  if(fst<con[0])stop();
  int c=fst;
  for(int i=1;i<len;i++){
    a.push_back(uu[i]<=c-1?--c:++c);
  }
  assert(a.size()==len);
  rep(i,len)if(a[i]<uu[i]||a[i]>n)stop();
}

int main(){
  cin>>n>>m;
  rep(i,m)cin>>a[i];
  cin>>q;
  rep(i,q)cin>>b[i];
  //assert
  assert(1<=n&&n<=1000000);
  assert(1<=m&&m<=n&&n<=200000);
  rep(i,m-1)assert(a[i]<a[i+1]);
  rep(i,m)assert(1<=a[i]&&a[i]<=n);
  rep(i,q)assert(1<=b[i]&&b[i]<=m);
  //解
  rep(i,q)tu[b[i]-1].push_back(i);
  rep(i,m){
    rep(j,tu[i].size()+1){
      int now=j==(int)0?-1:tu[i][j-1];
      int nxt=j>=(int)tu[i].size()?q:tu[i][j];
      if(i>0){
        now=lower_bound(tu[i-1].begin(),tu[i-1].end(),now)-tu[i-1].begin();
        nxt=lower_bound(tu[i-1].begin(),tu[i-1].end(),nxt)-tu[i-1].begin();
        int ma=0;
        for(int k=now;k<=nxt;k++)ma=max(ma,mv[i-1][k]);
        lo[i].push_back(ma+1);
      }else{
        lo[i].push_back(1);
      }
    }
    if(DEBUG){
      cerr<<i<<" lo:";
      rep(j,lo[i].size())cerr<<" "<<lo[i][j];
      cerr<<endl;
    }
    mv[i].push_back(a[i]);
    solve(mv[i],lo[i]);
    /*
    int p=a[i];
    mv[i].push_back(p);
    int pp=0;
    rep(j,tu[i].size()+1){
      int t=j==(int)tu[i].size()?q:tu[i][j];
      int nxt=j+1>=(int)tu[i].size()?q:tu[i][j+1];
      int pre;
      if(i==0)pre=0;
      else{
        int it=lower_bound(tu[i-1].begin(),tu[i-1].end(),t)-tu[i-1].begin();
        int nxt_it=lower_bound(tu[i-1].begin(),tu[i-1].end(),nxt)-tu[i-1].begin();
        pre=mv[i-1][it];
        if(it+1<mv[i-1].size())pre=max(pre,mv[i-1][it+1]);
        if(DEBUG)cerr<<i<<"-"<<j<<"-"<<pre<<"@"<<t<<endl;
        while(pp<=it){
          if(mv[i-1][pp]>=p){
            cout<<"NO"<<endl;return 0;
          }
          pp++;
        }
        pp--;
      }
      if(j>=tu[i].size())break;
      mv[i].push_back(pre<p-1?--p:++p);
      if(p>n){
        cout<<"NO"<<endl;return 0;
      }
      
    }
    */
    if(DEBUG){
      cerr<<mv[i][0];
      rep(j,tu[i].size())cerr<<" "<<tu[i][j]<<","<<mv[i][j+1];
      cerr<<endl;
      cerr<<"lo:";
      rep(j,lo[i].size())cerr<<" "<<lo[i][j];
      cerr<<endl;
    }
  }
  cout<<"YES"<<endl;
}
0