結果

問題 No.910 素数部分列
ユーザー jxkoko
提出日時 2019-10-20 23:17:23
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 6 ms / 1,000 ms
コード長 792 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 83,624 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-02 17:33:39
合計ジャッジ時間 1,950 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
#include <set> 
using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
typedef pair<pair<int, int>, int> PP;

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

const ll INF = 1e15;
const int MAX = 510000;
const ll MOD = 1000000007;


int main(void) {
	int N; cin >> N;
	string S; cin >> S;
	int ichi = 0, kyu = 0, ans = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '1') ichi++;
		else if (S[i] == '9') {
			kyu++;
			if (ichi > 0) {
				ans++; ichi--; kyu--;
			}
		}
		else ans++;
	}
	ans += min(ichi, kyu / 2); ichi -= min(ichi, kyu / 2);
	ans += ichi / 2;

	cout << ans << endl;
}
0