結果
問題 |
No.910 素数部分列
|
ユーザー |
![]() |
提出日時 | 2020-07-24 22:33:41 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 1,000 ms |
コード長 | 709 bytes |
コンパイル時間 | 1,644 ms |
コンパイル使用メモリ | 166,508 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 22:05:09 |
合計ジャッジ時間 | 3,233 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; 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; } int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; string s; cin >> s; int one = 0; int nine = 0; int ans = 0; rep(i, n){ if(s[i] == '3' || s[i] == '5' || s[i] == '7') ans++; if(s[i] == '1') one++; if(s[i] == '9'){ if(one > 0){ one--; ans++; }else{ nine++; } } } int x = min(nine / 2, one); ans += x; one -= x; ans += one / 2; cout << ans << endl; }