結果

問題 No.910 素数部分列
ユーザー sigma425sigma425
提出日時 2019-10-18 21:43:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 1,447 bytes
コンパイル時間 2,222 ms
コンパイル使用メモリ 202,060 KB
実行使用メモリ 5,564 KB
最終ジャッジ日時 2023-09-08 04:08:33
合計ジャッジ時間 4,223 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define show(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int N;string s; cin >> N >> s;
	int res = 0;
	V<int> v;
	for(char c: s){
		int d = c-'0';
		if(d == 3 || d == 5 || d == 7) res++;
		else v.pb(d);
	}
	{	//19
		V<int> nv;
		for(int x: v){
			if(x == 9 && !nv.empty() && nv.back() == 1){
				nv.pop_back();
				res++;
			}else{
				nv.pb(x);
			}
		}
		v = nv;
	}
	int one = 0, nine = 0;
	for(int x: v){
		if(x == 1) one++;
		else nine++;
	}
	int a = min(nine/2,one);
	res += a;
	one -= a;
	res += one/2;
	cout << res << endl;
}
0