結果
問題 | No.910 素数部分列 |
ユーザー |
![]() |
提出日時 | 2019-10-18 22:09:07 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 128 ms / 1,000 ms |
コード長 | 834 bytes |
コンパイル時間 | 2,839 ms |
コンパイル使用メモリ | 76,268 KB |
実行使用メモリ | 39,856 KB |
最終ジャッジ日時 | 2024-06-25 21:31:45 |
合計ジャッジ時間 | 9,428 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
ソースコード
import java.io.BufferedReader;import java.io.InputStreamReader;public class Main {public static void main(String[] args) throws Exception {BufferedReader br = new BufferedReader(new InputStreamReader(System.in));int n = Integer.parseInt(br.readLine());String s = br.readLine();br.close();int[] cnt = new int[10];for (int i = 0; i < n; i++) {cnt[s.charAt(i) - '0']++;}int ans = 0;ans += cnt[3];ans += cnt[5];ans += cnt[7];int cnt1 = 0;int cnt9 = 0;for (int i = 0; i < n; i++) {if (s.charAt(i) == '1') {cnt1++;} else if (s.charAt(i) == '9') {if (cnt1 > 0) {ans++;cnt1--;} else {cnt9++;}}}int val = Math.min(cnt1, cnt9 / 2);ans += val;cnt1 -= val;if (cnt1 > 0) {ans += cnt1 / 2;}System.out.println(ans);}}