結果

問題 No.910 素数部分列
ユーザー htensai
提出日時 2019-11-11 09:14:24
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,083 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 77,372 KB
実行使用メモリ 50,664 KB
最終ジャッジ日時 2024-09-15 05:09:50
合計ジャッジ時間 16,486 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20 WA * 26 TLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int[] counts = new int[10];
		StringBuilder sb = new StringBuilder();
		for (char c : arr) {
		    counts[c - '0']++;
		    if (c == '1' || c == '9') {
		        sb.append(c);
		    }
		}
		int total = counts[3] + counts[5] + counts[7];
		HashSet<Integer> set = new HashSet<>();
		for (int i = 0; i < sb.length(); i++) {
		    if (sb.charAt(i) == '9' || set.contains(i)) {
		        continue;
		    }
		    boolean flag = false;
		    for (int j = i + 1; j < sb.length(); j++) {
		        if (sb.charAt(j) == '9') {
		            flag = true;
		            set.add(j);
		            total++;
		            break;
		        }
		    }
		    if (flag) {
		        continue;
		    }
		    for (int j = i + 1; j < sb.length(); j++) {
		        if (sb.charAt(j) == '1') {
		            set.add(j);
		            total++;
		            break;
		        }
		    }
		}
		System.out.println(total);
	}
}
0