結果
問題 | No.910 素数部分列 |
ユーザー | tekihei2317 |
提出日時 | 2019-10-18 22:27:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 1,000 ms |
コード長 | 972 bytes |
コンパイル時間 | 1,529 ms |
コンパイル使用メモリ | 168,332 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 21:46:38 |
合計ジャッジ時間 | 2,954 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include<bits/stdc++.h> #define int long long using namespace std; template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; } template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; string s; cin>>s; vector<int> cnt(10); for(int i=0;i<N;i++){ cnt[s[i]-'0']++; } if(cnt[9]==0){ cout<<cnt[3]+cnt[5]+cnt[7]+cnt[1]/2<<endl; }else{ int ans=0; int c1=0,c9=0; for(int i=0;i<N;i++){ if(s[i]!='1' and s[i]!='9'){ ans++; continue; } if(s[i]=='1') c1++; else{ if(c1>0) c1--,ans++; else c9++; } } // cout<<c1<<' '<<c9<<endl; ans+=min(c9/2,c1); ans+=(c1-min(c9/2,c1))/2; cout<<ans<<endl; } return 0; }