結果

問題 No.1460 Max of Min
ユーザー QCFiumQCFium
提出日時 2021-03-31 22:56:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 967 ms / 2,000 ms
コード長 1,438 bytes
コンパイル時間 1,684 ms
コンパイル使用メモリ 173,280 KB
実行使用メモリ 4,792 KB
最終ジャッジ日時 2023-08-22 03:50:41
合計ジャッジ時間 34,193 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 7 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 6 ms
4,380 KB
testcase_07 AC 6 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 27 ms
4,380 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 5 ms
4,376 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 4 ms
4,384 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 6 ms
4,384 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 4 ms
4,376 KB
testcase_30 AC 5 ms
4,376 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 581 ms
4,504 KB
testcase_33 AC 130 ms
4,380 KB
testcase_34 AC 214 ms
4,380 KB
testcase_35 AC 46 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 319 ms
4,380 KB
testcase_38 AC 643 ms
4,380 KB
testcase_39 AC 133 ms
4,380 KB
testcase_40 AC 82 ms
4,380 KB
testcase_41 AC 49 ms
4,380 KB
testcase_42 AC 20 ms
4,380 KB
testcase_43 AC 247 ms
4,376 KB
testcase_44 AC 534 ms
4,380 KB
testcase_45 AC 5 ms
4,376 KB
testcase_46 AC 185 ms
4,376 KB
testcase_47 AC 265 ms
4,376 KB
testcase_48 AC 616 ms
4,380 KB
testcase_49 AC 399 ms
4,376 KB
testcase_50 AC 8 ms
4,380 KB
testcase_51 AC 296 ms
4,376 KB
testcase_52 AC 37 ms
4,376 KB
testcase_53 AC 336 ms
4,384 KB
testcase_54 AC 796 ms
4,504 KB
testcase_55 AC 802 ms
4,596 KB
testcase_56 AC 819 ms
4,672 KB
testcase_57 AC 840 ms
4,564 KB
testcase_58 AC 6 ms
4,380 KB
testcase_59 AC 811 ms
4,756 KB
testcase_60 AC 791 ms
4,556 KB
testcase_61 AC 825 ms
4,500 KB
testcase_62 AC 850 ms
4,772 KB
testcase_63 AC 3 ms
4,376 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 819 ms
4,556 KB
testcase_66 AC 820 ms
4,556 KB
testcase_67 AC 967 ms
4,504 KB
testcase_68 AC 835 ms
4,508 KB
testcase_69 AC 859 ms
4,672 KB
testcase_70 AC 824 ms
4,792 KB
testcase_71 AC 800 ms
4,784 KB
testcase_72 AC 805 ms
4,504 KB
testcase_73 AC 803 ms
4,556 KB
testcase_74 AC 791 ms
4,628 KB
testcase_75 AC 826 ms
4,784 KB
testcase_76 AC 801 ms
4,488 KB
testcase_77 AC 816 ms
4,488 KB
testcase_78 AC 826 ms
4,608 KB
testcase_79 AC 813 ms
4,548 KB
testcase_80 AC 844 ms
4,544 KB
testcase_81 AC 791 ms
4,496 KB
testcase_82 AC 832 ms
4,544 KB
testcase_83 AC 895 ms
4,492 KB
testcase_84 AC 26 ms
4,380 KB
testcase_85 AC 26 ms
4,376 KB
testcase_86 AC 27 ms
4,380 KB
testcase_87 AC 28 ms
4,376 KB
testcase_88 AC 27 ms
4,380 KB
testcase_89 AC 27 ms
4,376 KB
testcase_90 AC 27 ms
4,380 KB
testcase_91 AC 28 ms
4,376 KB
testcase_92 AC 27 ms
4,376 KB
testcase_93 AC 26 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}


int gcd(int a, int b) {
	while (a && b) {
		if (a > b) a %= b;
		else b %= a;
	}
	return a + b;
}

int main() {
	int k = ri();
	int64_t n;
	std::cin >> n;
	std::vector<int64_t> a(k + k);
	for (auto &i : a) std::cin >> i;
	std::reverse(a.begin() + k, a.end());
	
	if (n < k) {
		printf("%" PRId64 "\n", a[n]);
		return 0;
	}
	
	int threashold = k * k + k;
	
	int index[k + k];
	std::iota(index, index + k + k, 0);
	std::sort(index, index + k + k, [&] (int i, int j) { return a[i] > a[j]; });
	
	int l = 0;
	int r = k + k;
	while (r - l > 1) {
		int m = l + ((r - l) >> 1);
		
		std::vector<int> start;
		std::vector<int> move;
		for (int i = 0; i < m; i++) {
			if (index[i] < k) start.push_back(index[i]);
			else move.push_back(index[i] - k + 1);
		}
		
		bool ok = false;
		if (!move.size()) ok = false;
		else if (n > threashold) {
			int g = 0;
			for (auto j : move) g = gcd(g, j);
			for (auto i : start) for (auto j : move) if (i + j >= k && (n - i - j) % g == 0) ok = true;
		} else {
			bool dp[threashold + 1];
			memset(dp, 0, sizeof(dp));
			for (auto i : start) dp[i] = true;
			for (int i = 0; i < threashold; i++) {
				if (!dp[i]) continue;
				for (auto j : move) if (i + j <= threashold && i + j >= k) dp[i + j] = true;
			}
			if (dp[n]) ok = true;
		}
		if (ok) r = m;
		else l = m;
	}
	printf("%" PRId64 "\n", a[index[l]]);
	
	return 0;
}
0