結果

問題 No.910 素数部分列
ユーザー latte0119latte0119
提出日時 2019-10-18 21:53:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,369 bytes
コンパイル時間 1,651 ms
コンパイル使用メモリ 151,412 KB
実行使用メモリ 13,044 KB
最終ジャッジ日時 2023-09-07 21:59:53
合計ジャッジ時間 4,604 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 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 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 AC 1 ms
4,380 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 2 ms
4,384 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 50 ms
12,812 KB
testcase_40 AC 50 ms
12,800 KB
testcase_41 AC 50 ms
12,944 KB
testcase_42 AC 49 ms
12,760 KB
testcase_43 AC 49 ms
12,744 KB
testcase_44 AC 49 ms
12,948 KB
testcase_45 AC 50 ms
12,816 KB
testcase_46 AC 48 ms
12,812 KB
testcase_47 AC 51 ms
12,788 KB
testcase_48 AC 55 ms
12,804 KB
testcase_49 AC 54 ms
12,744 KB
testcase_50 AC 55 ms
12,920 KB
testcase_51 AC 5 ms
4,380 KB
testcase_52 AC 67 ms
12,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}



signed main(){

	int N;
	string S;
	cin>>N>>S;

	int ans=0;

	set<int>o,n;

	rep(i,N){
		if(S[i]=='1'){
			o.insert(i);
		}
		else if(S[i]=='9'){
			n.insert(i);
		}
		else ans++;
	}


	while(true){
		if(o.size()==0||n.size()==0)break;
		int ob=*o.begin();
		int oe=*o.rbegin();
		int nb=*n.begin();
		int ne=*n.rbegin();

		if(ob<nb){
			ans++;
			o.erase(ob);
			n.erase(ne);
			continue;
		}

		if(ne>oe){
			ans++;
			o.erase(ob);
			n.erase(ne);
			continue;
		}

		if(n.size()>=2){
			ans++;
			o.erase(oe);
			n.erase(nb);
			n.erase(*n.begin());
			continue;
		}
		break;
	}

	ans+=o.size()/2;
	cout<<ans<<endl;

	return 0;
}
0