結果

問題 No.647 明太子
ユーザー YamaKasaYamaKasa
提出日時 2018-04-19 17:19:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 439 ms / 4,500 ms
コード長 1,947 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 75,108 KB
実行使用メモリ 60,712 KB
最終ジャッジ日時 2023-09-09 11:46:07
合計ジャッジ時間 8,532 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,672 KB
testcase_01 AC 121 ms
55,768 KB
testcase_02 AC 120 ms
55,484 KB
testcase_03 AC 120 ms
56,104 KB
testcase_04 AC 124 ms
55,936 KB
testcase_05 AC 124 ms
55,832 KB
testcase_06 AC 124 ms
55,788 KB
testcase_07 AC 138 ms
55,940 KB
testcase_08 AC 140 ms
55,620 KB
testcase_09 AC 197 ms
59,104 KB
testcase_10 AC 202 ms
59,312 KB
testcase_11 AC 185 ms
56,436 KB
testcase_12 AC 199 ms
58,800 KB
testcase_13 AC 211 ms
59,064 KB
testcase_14 AC 394 ms
60,328 KB
testcase_15 AC 236 ms
59,584 KB
testcase_16 AC 205 ms
58,980 KB
testcase_17 AC 400 ms
60,596 KB
testcase_18 AC 424 ms
59,984 KB
testcase_19 AC 331 ms
60,712 KB
testcase_20 AC 311 ms
59,544 KB
testcase_21 AC 236 ms
59,416 KB
testcase_22 AC 439 ms
60,480 KB
testcase_23 AC 183 ms
56,396 KB
権限があれば一括ダウンロードができます

ソースコード

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();
		long []A = new long[N];
		long []B = new long[N];
		int count1 = 0;
		int count2 = 0;
		for(long 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();
		long []X = new long[M];
		long []Y = new long[M];
		int count3 = 0;
		int count4 = 0;
		for(long i = 0; i < 2 * M; i++){
			long 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;
//		System.out.println(sumM[101]);
//		System.out.println(sumM[117]);
		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();
				array.add(i + 1);
			}

		}

		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