結果

問題 No.1460 Max of Min
ユーザー e869120e869120
提出日時 2021-03-31 21:59:06
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,724 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 89,568 KB
実行使用メモリ 18,080 KB
最終ジャッジ日時 2023-08-22 01:44:43
合計ジャッジ時間 9,988 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
11,516 KB
testcase_01 AC 3 ms
11,492 KB
testcase_02 AC 3 ms
11,568 KB
testcase_03 AC 1,142 ms
13,732 KB
testcase_04 AC 1,141 ms
13,624 KB
testcase_05 AC 3 ms
11,496 KB
testcase_06 AC 1,263 ms
13,612 KB
testcase_07 AC 1,267 ms
13,576 KB
testcase_08 AC 3 ms
11,524 KB
testcase_09 AC 3 ms
11,592 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
testcase_65 -- -
testcase_66 -- -
testcase_67 -- -
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 <iostream>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int K;
long long N;
int A[1 << 22], B[1 << 22], C[1 << 22];
long long QA[1 << 22], QB[1 << 22];

int main() {
	// Crazy Solution
	// Step #1. 入力
	cin >> K >> N;
	for (int i = 0; i < K; i++) cin >> QA[i];
	for (int i = 0; i < K; i++) cin >> QB[i];

	// Step #2. 座標圧縮
	vector<long long> X;
	for (int i = 0; i < K; i++) X.push_back(QA[i]);
	for (int i = 0; i < K; i++) X.push_back(QB[i]);
	sort(X.begin(), X.end());
	X.erase(unique(X.begin(), X.end()), X.end());
	for (int i = 0; i < K; i++) A[i] = lower_bound(X.begin(), X.end(), QA[i]) - X.begin();
	for (int i = 0; i < K; i++) B[i] = lower_bound(X.begin(), X.end(), QB[i]) - X.begin();
	for (int i = 0; i < K; i++) C[K - i] = B[i];

	// Step #3. 愚直解
	long long rem = min(N, 1LL * K * K);
	for (int i = K; i <= rem; i++) A[i] = -1;
	for (int i = 0; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			if (i + j < K) continue;
			A[i + j] = max(A[i + j], min(A[i], C[j]));
		}
	}
	for (int i = K; i <= rem; i++) {
		for (int j = 1; j <= K; j++) {
			A[i + j] = max(A[i + j], min(A[i], C[j]));
		}
	}
	if (rem == N) {
		cout << X[A[N]] << endl;
		return 0;
	}
	
	// Step #4. 周期を見る
	long long pr = -1;
	for (long long i = rem - 1; i >= K; i--) {
		bool flag = false;
		for (int j = 0; j < K; j++) {
			if (A[rem - K + j] != A[i - K + j]) { flag = true; break; }
		}
		if (flag == false) { pr = rem - i; break; }
	}
	
	// Step #5. 答えを出力
	long long idx = (rem - pr) + (N - rem) % pr;
	cout << X[A[idx]] << endl;
	return 0;
}
0