結果

問題 No.910 素数部分列
ユーザー ate
提出日時 2019-10-18 23:11:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,822 bytes
コンパイル時間 2,513 ms
コンパイル使用メモリ 192,956 KB
最終ジャッジ日時 2025-01-07 23:44:55
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of ‘main’ with no type [-Wreturn-type]
   18 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define rep(i,n) for(ll i=0;i<(n);++i)
#define reps(i,n) for(ll i=1;i<=(n);++i)
using ll = long long;
using str = string;
constexpr long long INF = (1LL<<60);
constexpr long long MOD = (1e9+7);
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
inline void dump(){cout<<endl;}
template<class Head,class... Tail>inline void dump(Head&& head, Tail&&... tail){cout<<head<<", ";dump(forward<Tail>(tail)...);}
template<typename T>inline istream &operator>>(istream&input,vector<T>&v){for(auto &elemnt:v)input>>elemnt;return input;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}

main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  ll n;
  string s;
  cin>>n>>s;
  
  ll one,three,five,seven,nine,ans;
  one=three=five=seven=nine=ans=0;
  rep(i,n){
    if(s[i]=='1')one++;
    if(s[i]=='3'){
      three++;
      if(one){
        one--;
        three--;
        ans++;
      }
    }
    if(s[i]=='5')five++;
    if(s[i]=='7'){
      seven++;
      if(nine){
        nine--;
        seven--;
        ans++;
      }
      else if(one){
        one--;
        seven--;
        ans++;
      }
    }
    if(s[i]=='9'){
      nine++;
      if(one){
        one--;
        nine--;
        ans++;
      }
      else if(five){
        five--;
        nine--;
        ans++;
      }
      else if(seven){
        seven--;
        nine--;
        ans++;
      }
    }
  }
  ans += three;
  ans += five;
  ans += seven;
  ans += one/2;
  cout<<(ans)<<endl;


}
0