結果

問題 No.647 明太子
ユーザー YamaKasaYamaKasa
提出日時 2018-04-19 16:14:42
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,839 bytes
コンパイル時間 3,174 ms
コンパイル使用メモリ 74,220 KB
実行使用メモリ 60,732 KB
最終ジャッジ日時 2023-09-09 11:45:17
合計ジャッジ時間 10,112 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
55,288 KB
testcase_01 AC 140 ms
55,276 KB
testcase_02 AC 136 ms
52,912 KB
testcase_03 AC 131 ms
55,752 KB
testcase_04 AC 141 ms
55,680 KB
testcase_05 AC 140 ms
55,488 KB
testcase_06 AC 136 ms
55,660 KB
testcase_07 AC 150 ms
56,412 KB
testcase_08 AC 151 ms
55,728 KB
testcase_09 AC 214 ms
58,852 KB
testcase_10 AC 221 ms
58,740 KB
testcase_11 AC 198 ms
56,244 KB
testcase_12 AC 215 ms
58,588 KB
testcase_13 AC 231 ms
58,908 KB
testcase_14 AC 422 ms
60,708 KB
testcase_15 AC 248 ms
59,540 KB
testcase_16 AC 220 ms
58,768 KB
testcase_17 AC 433 ms
60,116 KB
testcase_18 AC 449 ms
60,412 KB
testcase_19 AC 348 ms
59,472 KB
testcase_20 AC 319 ms
60,184 KB
testcase_21 AC 248 ms
59,568 KB
testcase_22 AC 456 ms
60,732 KB
testcase_23 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int []A = new int[N];
		int []B = new int[N];
		int count1 = 0;
		int count2 = 0;
		for(int i = 0; i < 2 * N; i++){
			int k = scanner.nextInt();
		    if(i % 2 == 0) {
		    	A[count1] = k;
		    	count1++;
		    }else if(i % 2 == 1){
		    	B[count2] = k;
		    	count2++;
		    }
		}
		int M = scanner.nextInt();
		int []X = new int[M];
		int []Y = new int[M];
		int count3 = 0;
		int count4 = 0;
		for(int i = 0; i < 2 * M; i++){
			int k = scanner.nextInt();
		    if(i % 2 == 0) {
		    	X[count3] = k;
		    	count3++;
		    }else if(i % 2 == 1){
		    	Y[count4] = k;
		    	count4++;
		    }
		}
		scanner.close();
		int []sumM = new int[M];
		Arrays.fill(sumM, 0);

//		for(int i = 0; i < N; i++) {
//			System.out.println(A[i] + ", " + B[i]);
//		}
//		for(int i = 0; i < M; i++) {
//		System.out.println(X[i] + ", " + Y[i]);
//	}

		int flag = 0;
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < M; j++) {
				if(X[j] <= A[i] && Y[j] >= B[i]) {
					sumM[j]++;
					flag++;
				}
			}
		}
		// 該当なし
		if(flag == 0) {
			System.out.println("0");
			System.exit(0);
		}
//		for(int i = 0; i < M; i++) {
//			System.out.println(sumM[i]);
//		}
		int k = 0;
		int max = sumM[0];
		int ans = 0;
		ArrayList<Integer> array = new ArrayList<Integer>();
		for(int i = 0; i < M; i++) {
			k = sumM[i];
			if(k == max) {
				array.add(i + 1);
				ans = i + 1;
			}else if(k > max) {
				max = k;
				ans = i + 1;
				array.clear();
			}
		}
		if(array.size() > 1) {
			for(int i = 0; i < array.size(); i++) {
				System.out.println(array.get(i));
			}
		}else if(max != 0){
			System.out.println(ans);
		}
	}
}
0