結果
問題 |
No.910 素数部分列
|
ユーザー |
![]() |
提出日時 | 2019-10-19 16:31:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 1,000 ms |
コード長 | 1,019 bytes |
コンパイル時間 | 1,429 ms |
コンパイル使用メモリ | 166,356 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-27 06:51:57 |
合計ジャッジ時間 | 2,980 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; //template #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(a);i>(b);i--) #define ALL(v) (v).begin(),(v).end() typedef long long int ll; typedef pair<ll, ll> P; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);} const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff; //template end int main(){ int n; scanf("%d",&n); string s; cin>>s; int ans=0,one=0,nine=0; rep(i,0,n){ if(s[i]=='3'||s[i]=='5'||s[i]=='7')ans++; if(s[i]=='1')one++; if(s[i]=='9'){ if(one)one--,ans++; else nine++; } } int add=min(one,nine/2); ans+=add; one-=add; printf("%d\n",ans+one/2); return 0; }