結果
問題 | No.910 素数部分列 |
ユーザー |
![]() |
提出日時 | 2020-08-17 14:05:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 1,000 ms |
コード長 | 709 bytes |
コンパイル時間 | 4,105 ms |
コンパイル使用メモリ | 191,964 KB |
最終ジャッジ日時 | 2025-01-13 02:31:05 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; }