結果
問題 |
No.910 素数部分列
|
ユーザー |
![]() |
提出日時 | 2019-10-19 09:03:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 1,000 ms |
コード長 | 927 bytes |
コンパイル時間 | 1,584 ms |
コンパイル使用メモリ | 170,504 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 11:07:38 |
合計ジャッジ時間 | 3,230 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; int ans=0; vector<int> a; for(int i=0;i<N;i++){ int d=s[i]-'0'; if(d==3 or d==5 or d==7) ans++; else a.push_back(d); } int c1=0,c9=0; for(int i=0;i<a.size();i++){ if(a[i]==1) c1++; else{ if(c1>0){ // delete 19 c1--; ans++; }else{ c9++; } } } // cout<<c1<<' '<<c9<<endl; // delete 991 ans+=min(c9/2,c1); // delete 11 ans+=(c1-min(c9/2,c1))/2; cout<<ans<<endl; return 0; }