結果

問題 No.1460 Max of Min
ユーザー QCFiumQCFium
提出日時 2021-03-31 22:47:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,333 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 174,816 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-22 03:33:02
合計ジャッジ時間 14,162 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 RE -
testcase_02 AC 1 ms
4,380 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 1 ms
4,376 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 AC 49 ms
4,788 KB
testcase_33 AC 220 ms
4,376 KB
testcase_34 AC 21 ms
4,376 KB
testcase_35 AC 7 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 17 ms
4,380 KB
testcase_38 AC 291 ms
4,868 KB
testcase_39 AC 7 ms
4,380 KB
testcase_40 AC 10 ms
4,380 KB
testcase_41 AC 7 ms
4,380 KB
testcase_42 AC 6 ms
4,380 KB
testcase_43 AC 10 ms
4,376 KB
testcase_44 AC 14 ms
4,868 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 8 ms
4,380 KB
testcase_47 AC 6 ms
4,376 KB
testcase_48 AC 16 ms
4,788 KB
testcase_49 AC 33 ms
4,388 KB
testcase_50 AC 3 ms
4,376 KB
testcase_51 AC 10 ms
4,380 KB
testcase_52 AC 4 ms
4,380 KB
testcase_53 AC 28 ms
4,388 KB
testcase_54 AC 194 ms
5,052 KB
testcase_55 AC 54 ms
5,024 KB
testcase_56 AC 628 ms
4,948 KB
testcase_57 AC 19 ms
4,960 KB
testcase_58 RE -
testcase_59 AC 33 ms
5,244 KB
testcase_60 AC 51 ms
5,076 KB
testcase_61 AC 168 ms
5,056 KB
testcase_62 AC 61 ms
5,008 KB
testcase_63 AC 3 ms
4,376 KB
testcase_64 AC 3 ms
4,376 KB
testcase_65 AC 26 ms
4,984 KB
testcase_66 AC 77 ms
5,024 KB
testcase_67 TLE -
testcase_68 -- -
testcase_69 -- -
testcase_70 -- -
testcase_71 -- -
testcase_72 -- -
testcase_73 -- -
testcase_74 -- -
testcase_75 -- -
testcase_76 -- -
testcase_77 -- -
testcase_78 -- -
testcase_79 -- -
testcase_80 -- -
testcase_81 -- -
testcase_82 -- -
testcase_83 -- -
testcase_84 -- -
testcase_85 -- -
testcase_86 -- -
testcase_87 -- -
testcase_88 -- -
testcase_89 -- -
testcase_90 -- -
testcase_91 -- -
testcase_92 -- -
testcase_93 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = 1.5 * 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]; });
	
	std::set<int> start;
	std::set<int> move;
	for (auto i : index) {
		if (i < k) start.insert(i);
		else move.insert(i - k + 1);
		
		if (!move.size()) continue;
		
		int g = 0;
		for (auto j : move) g = gcd(g, j);
		
		// std::cerr << "added " << i << std::endl;
		bool ok = false;
		if (n > threashold) {
			assert(0);
			for (auto i : start) if ((n - i) % 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) {
			printf("%" PRId64 "\n", a[i]);
			return 0;
		}
	}
	assert(0);
	
	return 0;
}
0