結果

問題 No.910 素数部分列
ユーザー LayCurseLayCurse
提出日時 2019-11-10 18:27:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 2,361 bytes
コンパイル時間 2,525 ms
コンパイル使用メモリ 210,532 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-13 07:49:56
合計ジャッジ時間 4,441 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 1 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 1 ms
4,348 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 4 ms
4,352 KB
testcase_24 AC 4 ms
4,348 KB
testcase_25 AC 4 ms
4,352 KB
testcase_26 AC 5 ms
4,348 KB
testcase_27 AC 4 ms
4,352 KB
testcase_28 AC 4 ms
4,348 KB
testcase_29 AC 3 ms
4,352 KB
testcase_30 AC 4 ms
4,348 KB
testcase_31 AC 4 ms
4,348 KB
testcase_32 AC 4 ms
4,348 KB
testcase_33 AC 4 ms
4,348 KB
testcase_34 AC 3 ms
4,348 KB
testcase_35 AC 4 ms
4,352 KB
testcase_36 AC 4 ms
4,348 KB
testcase_37 AC 4 ms
4,352 KB
testcase_38 AC 3 ms
4,352 KB
testcase_39 AC 3 ms
4,348 KB
testcase_40 AC 3 ms
4,352 KB
testcase_41 AC 4 ms
4,348 KB
testcase_42 AC 4 ms
4,348 KB
testcase_43 AC 3 ms
4,348 KB
testcase_44 AC 3 ms
4,352 KB
testcase_45 AC 3 ms
4,348 KB
testcase_46 AC 3 ms
4,348 KB
testcase_47 AC 4 ms
4,348 KB
testcase_48 AC 2 ms
4,352 KB
testcase_49 AC 3 ms
4,352 KB
testcase_50 AC 3 ms
4,348 KB
testcase_51 AC 3 ms
4,352 KB
testcase_52 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
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 rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
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');
  }
}
template<class S> inline int arrEraseVal_L(S val1, S val2, S val3, int &sz, S a[]){
  int i;
  int n = sz;
  sz = 0;
  for(i=(0);i<(n);i++){
    if(a[i]!=val1 && a[i]!=val2 && a[i]!=val3){
      a[sz++] = a[i];
    }
  }
  return n - sz;
}
int N;
char S[200002];
int main(){
  int i;
  int k;
  int c1 = 0;
  int c9 = 0;
  int res;
  rd(N);
  rd(S);
  for(i=(0);i<(N);i++){
    S[i] -= '0';
  }
  res =arrEraseVal_L((char)3,(char)5,(char)7,N,S);
  for(i=(0);i<(N);i++){
    if(S[i]==1){
      c1++;
      continue;
    }
    if(c1){
      c1--;
      res++;
      continue;
    }
    c9++;
  }
  res += (k =min_L(c9/2, c1));
  res += (c1-k) / 2;
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191108-1

// --- original code ---
// int N;
// char S[200002];
// {
//   int k, c1 = 0, c9 = 0, res;
//   rd(N,S);
//   rep(i,N) S[i] -= '0';
//   res = arrEraseVal((char)3,(char)5,(char)7,N,S);
//   rep(i,N){
//     if(S[i]==1) c1++, continue;
//     if(c1) c1--, res++, continue;
//     c9++;
//   }
//   res += (k = min(c9/2, c1));
//   res += (c1-k) / 2;
//   wt(res);
// }
0