結果

問題 No.910 素数部分列
ユーザー Ogtsn99Ogtsn99
提出日時 2019-10-18 21:57:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,566 bytes
コンパイル時間 1,488 ms
コンパイル使用メモリ 164,852 KB
実行使用メモリ 7,884 KB
最終ジャッジ日時 2023-09-07 22:22:44
合計ジャッジ時間 6,934 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
7,884 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 WA -
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 33 ms
4,380 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 68 ms
4,380 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
signed main(void){
    int n; cin>>n;
    string s; cin>>s;
    int ans = 0;
    int one = -1, nine = -1;
    rep(i,n){
        if(s[i]=='3'|| s[i] == '5'|| s[i] == '7'){
            ans++;
            s[i] = '?';
        }
        if(s[i] == '1') one = i;
        if(s[i] == '9') {
            nine = i;
            if(one != -1) {
                s[one] = s[nine] = '?';
                one = -1; nine = -1;
                ans++;
            }
        }
    }
    bool update = true;
    while(update){
        update = false;
        one = -1; nine = -1;
        rep(i,n){
            if(s[i] == '1') one = i;
            if(s[i] == '9') {
                nine = i;
                if(one != -1) {
                    s[one] = s[nine] = '?';
                    one = -1; nine = -1;
                    ans++;
                    update = true;
                }
            }
        }
    }
    int c1=0, c9 = 0;
    rep(i,n){
        if(s[i] == '1') c1++;
        else if(s[i] == '9') c9++;
    }
    ans += min(c9/2, c1);
    cout<<ans<<endl;
}
0