結果

問題 No.1211 円環はお断り
ユーザー ks2mks2m
提出日時 2020-08-30 14:34:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,274 bytes
コンパイル時間 4,920 ms
コンパイル使用メモリ 73,916 KB
実行使用メモリ 70,812 KB
最終ジャッジ日時 2023-08-09 12:32:42
合計ジャッジ時間 18,925 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
47,188 KB
testcase_01 AC 44 ms
49,368 KB
testcase_02 AC 45 ms
49,480 KB
testcase_03 AC 45 ms
49,528 KB
testcase_04 AC 45 ms
48,980 KB
testcase_05 AC 45 ms
49,456 KB
testcase_06 AC 46 ms
49,208 KB
testcase_07 AC 48 ms
49,976 KB
testcase_08 AC 44 ms
49,168 KB
testcase_09 AC 50 ms
48,060 KB
testcase_10 WA -
testcase_11 AC 50 ms
49,976 KB
testcase_12 AC 47 ms
49,356 KB
testcase_13 AC 398 ms
64,476 KB
testcase_14 WA -
testcase_15 AC 378 ms
60,176 KB
testcase_16 AC 648 ms
66,588 KB
testcase_17 AC 157 ms
54,912 KB
testcase_18 AC 360 ms
60,396 KB
testcase_19 AC 171 ms
55,012 KB
testcase_20 WA -
testcase_21 AC 187 ms
56,072 KB
testcase_22 AC 415 ms
64,780 KB
testcase_23 AC 475 ms
64,636 KB
testcase_24 AC 320 ms
64,036 KB
testcase_25 AC 97 ms
54,332 KB
testcase_26 AC 426 ms
64,216 KB
testcase_27 AC 333 ms
64,440 KB
testcase_28 AC 447 ms
64,780 KB
testcase_29 AC 428 ms
66,992 KB
testcase_30 AC 550 ms
66,372 KB
testcase_31 AC 293 ms
60,136 KB
testcase_32 AC 628 ms
67,000 KB
testcase_33 AC 804 ms
68,980 KB
testcase_34 AC 795 ms
69,332 KB
testcase_35 AC 800 ms
68,876 KB
testcase_36 AC 833 ms
70,812 KB
testcase_37 AC 835 ms
70,660 KB
testcase_38 AC 805 ms
69,536 KB
testcase_39 AC 818 ms
69,948 KB
testcase_40 AC 271 ms
60,792 KB
testcase_41 AC 46 ms
49,140 KB
testcase_42 AC 45 ms
49,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {
	static int n, k;
	static int[] a;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		n = Integer.parseInt(sa[0]);
		k = Integer.parseInt(sa[1]);
		sa = br.readLine().split(" ");
		long sum = 0;
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
			sum += a[i];
		}
		br.close();

		long ok = 0;
		long ng = sum / k + 1;
		while (Math.abs(ok - ng) > 1) {
			long mid = (ok + ng) / 2;
			if (can(mid)) {
				ok = mid;
			} else {
				ng = mid;
			}
		}
		System.out.println(ok);
	}

	static boolean can(long mid) {
		Set<Integer> set = new HashSet<>();
		boolean flg = false;
		label:
		for (int i = 0; i < n; i++) {
			long sum = 0;
			int cnt = 0;
			for (int j = i; j < i + n; j++) {
				int idx = j % n;
				sum += a[idx];
				if (sum >= mid) {
					cnt++;
					sum = 0;
					if (!flg && !set.add(idx)) {
						flg = true;
						i = idx;
						continue label;
					}
				}
			}
			if (cnt >= k) {
				return true;
			}
			if (flg) {
				break;
			}
		}
		return false;
	}
}
0