結果

問題 No.1508 Avoid being hit
ユーザー LayCurseLayCurse
提出日時 2021-05-14 22:52:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 37 ms / 3,000 ms
コード長 3,926 bytes
コンパイル時間 3,577 ms
コンパイル使用メモリ 220,688 KB
実行使用メモリ 9,964 KB
最終ジャッジ日時 2023-07-25 12:55:04
合計ジャッジ時間 6,868 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
8,904 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 33 ms
9,096 KB
testcase_17 AC 18 ms
6,524 KB
testcase_18 AC 13 ms
5,812 KB
testcase_19 AC 27 ms
8,088 KB
testcase_20 AC 37 ms
9,964 KB
testcase_21 AC 25 ms
7,832 KB
testcase_22 AC 32 ms
8,848 KB
testcase_23 AC 34 ms
9,312 KB
testcase_24 AC 36 ms
9,652 KB
testcase_25 AC 32 ms
9,248 KB
testcase_26 AC 3 ms
4,384 KB
testcase_27 AC 16 ms
6,256 KB
testcase_28 AC 16 ms
6,328 KB
testcase_29 AC 33 ms
9,304 KB
testcase_30 AC 17 ms
6,480 KB
testcase_31 AC 29 ms
8,392 KB
testcase_32 AC 31 ms
8,800 KB
testcase_33 AC 8 ms
4,904 KB
testcase_34 AC 26 ms
8,188 KB
testcase_35 AC 4 ms
4,384 KB
testcase_36 AC 14 ms
6,164 KB
testcase_37 AC 7 ms
4,512 KB
testcase_38 AC 20 ms
7,312 KB
testcase_39 AC 13 ms
5,728 KB
testcase_40 AC 27 ms
8,260 KB
testcase_41 AC 15 ms
6,132 KB
testcase_42 AC 27 ms
8,348 KB
testcase_43 AC 32 ms
9,188 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class T> struct cLtraits_identity{
  using type = T;
}
;
template<class T> using cLtraits_try_make_signed =
  typename conditional<
    is_integral<T>::value,
    make_signed<T>,
    cLtraits_identity<T>
    >::type;
template <class S, class T> struct cLtraits_common_type{
  using tS = typename cLtraits_try_make_signed<S>::type;
  using tT = typename cLtraits_try_make_signed<T>::type;
  using type = typename common_type<tS,tT>::type;
}
;
template<class S, class T> inline auto max_L(S a, T b)
-> typename cLtraits_common_type<S,T>::type{
  return (typename cLtraits_common_type<S,T>::type) a >= (typename cLtraits_common_type<S,T>::type) b ? a : b;
}
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    my_putchar_unlocked(c[i]);
  }
}
int N;
int Q;
int A[100000];
int B[100000];
int res[100000];
int main(){
  int i;
  set<int> s;
  rd(N);
  rd(Q);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(Q);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1);
    }
  }
  {
    int e98WHCEY;
    for(e98WHCEY=(0);e98WHCEY<(Q);e98WHCEY++){
      rd(B[e98WHCEY]);B[e98WHCEY] += (-1);
    }
  }
  for(i=(0);i<(Q);i++){
    s.insert(i);
  }
  while(s.size()){
    i = *s.begin();
    s.erase(i);
    while(res[i] == A[i] || res[i] == B[i]){
      res[i]++;
    }
    if(i-1 >= 0 && res[i-1] < res[i]-1){
      res[i-1] = res[i] - 1;
      s.insert(i-1);
    }
    if(i+1 <  Q && res[i+1] < res[i]-1){
      res[i+1] = res[i] - 1;
      s.insert(i+1);
    }
  }
  int tU__gIr_;
  int a2conNHc;
  if(Q==0){
    a2conNHc = 0;
  }
  else{
    a2conNHc = res[0];
    for(tU__gIr_=(1);tU__gIr_<(Q);tU__gIr_++){
      a2conNHc = max_L(a2conNHc, res[tU__gIr_]);
    }
  }
  if(a2conNHc>= N){
    wt_L("NO");
    wt_L('\n');
    return 0;
  }
  wt_L("YES");
  wt_L('\n');
  wt_L(res[0]+1);
  wt_L('\n');
  for(i=(0);i<(Q);i++){
    wt_L(res[i]+1);
    wt_L('\n');
  }
  return 0;
}
// cLay version 20210508-1 [beta]

// --- original code ---
// int N, Q, A[1d5], B[];
// int res[1d5];
// {
//   set<int> s;
//   rd(N,Q,(A--)(Q),(B--)(Q));
// 
//   rep(i,Q) s.insert(i);
//   while(s.size()){
//     i = *s.begin();
//     s.erase(i);
//     while(res[i] == A[i] || res[i] == B[i]) res[i]++;
//     if(i-1 >= 0 && res[i-1] < res[i]-1) res[i-1] = res[i] - 1, s.insert(i-1);
//     if(i+1 <  Q && res[i+1] < res[i]-1) res[i+1] = res[i] - 1, s.insert(i+1);
//   }
// 
//   if(max(res(Q)) >= N) wt("NO"), return 0;
// 
//   wt("YES");
//   wt(res[0]+1);
//   rep(i,Q) wt(res[i]+1);
// }
0