結果

問題 No.910 素数部分列
ユーザー 👑 CleyL
提出日時 2019-10-18 23:37:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 730 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 65,148 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-25 19:57:32
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 8 WA * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;
string z;
int main(){
  int n;
  string s;cin>>n>>s;
  int ans = 0;
  for(int i = 0; n > i; i++){
    if(s[i] == '3' || s[i] == '5' || s[i] == '7')ans++;
    else z.push_back(s[i]);
  }
  int tmp = 0;
  int ans2 = 0;
  for(int i = z.size()-1;0 <= i; i--){
    if(z[i] == '1'){
      if(tmp){
        ans2++;
        tmp--;
      }
    }else{
      tmp++;
    }
  }
  int nw = 0;
  int nine = 0;
  int one = 0;
  for(int i = 0; ans2 > nw; i++){
    if(z[i] == '1')nw++;
    else nine++;
  }
  nw = 0;
  for(int i = z.size()-1; ans2 > nw; i--){
    if(z[i] == '9')nw++;
    else one++;
  }
  int ans3 = 0;
  ans3 += min(nine/2,one);
  ans3 += (ans3-one)/2;
  cout << ans+ans2+ans3 << endl;
}
0