結果

問題 No.910 素数部分列
ユーザー kappybar
提出日時 2020-03-30 22:23:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 9 ms / 1,000 ms
コード長 1,487 bytes
コンパイル時間 1,358 ms
コンパイル使用メモリ 168,064 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-23 05:13:31
合計ジャッジ時間 2,977 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;


int main() {
        int n;
        cin >> n;
        string s;
        cin >> s;
        int cnt = 0;
        rep(i,n){
                if(s[i]-'0' != 1 && s[i]-'0' != 9) cnt ++;
        }
        int i = 0,j = 0;
        while(i < n && j < n){
                while(s[i]-'0' != 1 && i < n) i++;
                if(j < i) j = i;
                if(j >= n) break;
                while(s[j]-'0' != 9 && j < n) j ++;
                if(i < n && j < n){
                        cnt ++;
                        s[i] = '3';s[j] = '3';
                }
        }

        int k = 0;
        i = 0,j = 0;
        while(i < n && j < n && k < n){
                while(s[i] - '0' != 9 && i < n) i++;
                j = i + 1;
                if(j >= n) break;
                while(s[j] -'0' != 9 && j < n) j ++;
                if(k < j) k = j;
                if(k >= n) break;
                while(s[k] -'0' != 1 && k < n) k ++;
                if(i < n && j < n && k < n){
                        cnt ++;
                        s[i] = '3';s[j]='3';s[k] = '3';
                }
        }
        
        i = 0;
        int one = 0;
        while(i < n){
                if(s[i]-'0' == 1)  one ++;
                i ++;
        }

        cnt += one/2;
        cout << cnt << endl;

        return 0;  
}
0