結果

問題 No.930 数列圧縮
ユーザー LayCurseLayCurse
提出日時 2019-11-22 21:51:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 2,069 bytes
コンパイル時間 2,566 ms
コンパイル使用メモリ 207,320 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 11:03:36
合計ジャッジ時間 4,087 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 5 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 4 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 5 ms
5,376 KB
testcase_16 AC 6 ms
5,376 KB
testcase_17 AC 6 ms
5,376 KB
testcase_18 AC 6 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 6 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 5 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  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){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int A[100000];
int ress;
int res[100000];
int main(){
  int i;
  int k = 0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  if(A[0] >= A[N-1]){
    wt_L("No");
    wt_L('\n');
    return 0;
  }
  wt_L("Yes");
  wt_L('\n');
  for(i=(0);i<(N-1);i++){
    A[k++] = A[i];
    while(k >= 2 && A[k-2] < A[k-1]){
      res[ress++] = A[--k];
    }
  }
  A[k++] = A[N-1];
  while(k >= 2 && A[k-2] < A[k-1]){
    res[ress++] = A[k-2];
    A[k-2] = A[k-1];
    k--;
  }
  {
    int t_ynMSdg;
    if(ress==0){
      putchar_unlocked('\n');
    }
    else{
      for(t_ynMSdg=(0);t_ynMSdg<(ress-1);t_ynMSdg++){
        wt_L(res[t_ynMSdg]);
        wt_L(' ');
      }
      wt_L(res[t_ynMSdg]);
      wt_L('\n');
    }
  }
  return 0;
}
// cLay varsion 20191111-2

// --- original code ---
// int N, A[1d5];
// int ress, res[1d5];
// {
//   int k = 0;
//   rd(N,A(N));
//   if(A[0] >= A[N-1]) wt("No"), return 0;
//   wt("Yes");
//   rep(i,N-1){
//     A[k++] = A[i];
//     while(k >= 2 && A[k-2] < A[k-1]) res[ress++] = A[--k];
//   }
//   A[k++] = A[N-1];
//   while(k >= 2 && A[k-2] < A[k-1]){
//     res[ress++] = A[k-2];
//     A[k-2] = A[k-1];
//     k--;
//   }
//   wt(res(ress));
// }
0