結果

問題 No.647 明太子
ユーザー YamaKasaYamaKasa
提出日時 2018-04-19 17:00:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,841 bytes
コンパイル時間 2,224 ms
コンパイル使用メモリ 74,188 KB
実行使用メモリ 60,832 KB
最終ジャッジ日時 2023-09-09 11:45:57
合計ジャッジ時間 9,097 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,592 KB
testcase_01 AC 121 ms
55,540 KB
testcase_02 AC 122 ms
55,548 KB
testcase_03 AC 121 ms
56,020 KB
testcase_04 AC 124 ms
55,880 KB
testcase_05 AC 123 ms
54,364 KB
testcase_06 AC 129 ms
56,684 KB
testcase_07 AC 140 ms
55,996 KB
testcase_08 AC 137 ms
56,184 KB
testcase_09 AC 197 ms
58,796 KB
testcase_10 AC 201 ms
58,564 KB
testcase_11 AC 185 ms
56,380 KB
testcase_12 AC 195 ms
58,932 KB
testcase_13 AC 210 ms
58,588 KB
testcase_14 AC 387 ms
60,108 KB
testcase_15 AC 232 ms
59,488 KB
testcase_16 AC 200 ms
58,764 KB
testcase_17 AC 407 ms
60,428 KB
testcase_18 AC 440 ms
60,272 KB
testcase_19 AC 327 ms
60,832 KB
testcase_20 AC 315 ms
60,076 KB
testcase_21 AC 235 ms
60,084 KB
testcase_22 AC 440 ms
60,556 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 = 1;
				}
			}
		}
		// 該当なし
		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