提出 #56582789


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	int n, k;
	cin >> n >> k;

	vector<ll> a(n), b(n);
	for (int i=0; i<n; i++){
		cin >> a[i] >> b[i];
	}

	// x=1,2,...,50 に対して、その上位 K 個を求める
	vector data(51, vector<ll>(k, -1));
	for (int x=1; x<51; x++){
		for (int i=0; i<n; i++){
			ll t = a[i] * x + b[i];
			for (int j=0; j<k; j++){
				if (data[x][j] == -1
					|| a[data[x][j]] * x + b[data[x][j]] <= t) {
					for (int l=k-1; l>=j+1; l--){
						data[x][l] = data[x][l-1];
					}
					data[x][j] = i;
					break;
				}
			}
		}
	}

	ll ans = 0;
	vector<bool> used(n);

	// p_1, ..., p_k を列挙
	auto dfs = [&](auto self, int num, ll now_value) -> void {
		if (num == k){			
			ans = max(ans, now_value);
			return;
		}

		ll t = min(now_value, 50LL);
		int cnt = 0;
		for (int i=0; i<k; i++){
			if (cnt >= k-num) break;
			if (used[data[t][i]]) continue;
			used[data[t][i]] = true;
			cnt += 1;
			self(self, num+1, a[data[t][i]] * now_value + b[data[t][i]]);
			used[data[t][i]] = false;
		}
	};

	dfs(dfs, 0, 1);
	cout << ans << endl;
	
}

提出情報

提出日時
問題 F - Maximum Composition
ユーザ shobonvip
言語 C++ 20 (gcc 12.2)
得点 500
コード長 1165 Byte
結果 AC
実行時間 260 ms
メモリ 6516 KiB

ジャッジ結果

セット名 Sample All After Contest
得点 / 配点 0 / 0 500 / 500 0 / 0
結果
AC × 2
AC × 36
AC × 1
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 02_maximum_00.txt, 02_maximum_01.txt, 02_maximum_02.txt, 02_maximum_03.txt, 02_maximum_04.txt, 03_handmade_00.txt, 03_handmade_01.txt, 03_handmade_02.txt, 03_handmade_03.txt, 03_handmade_04.txt, 03_handmade_05.txt, 03_handmade_06.txt, 03_handmade_07.txt, 03_handmade_08.txt, 03_handmade_09.txt, 03_handmade_10.txt, 03_handmade_11.txt, 03_handmade_12.txt, 03_handmade_13.txt
After Contest 04_after_contest_00.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3560 KiB
00_sample_01.txt AC 1 ms 3556 KiB
01_random_00.txt AC 54 ms 6248 KiB
01_random_01.txt AC 90 ms 6076 KiB
01_random_02.txt AC 47 ms 4700 KiB
01_random_03.txt AC 204 ms 4704 KiB
01_random_04.txt AC 74 ms 5552 KiB
01_random_05.txt AC 93 ms 6240 KiB
01_random_06.txt AC 55 ms 4944 KiB
01_random_07.txt AC 69 ms 5352 KiB
01_random_08.txt AC 54 ms 4704 KiB
01_random_09.txt AC 91 ms 6028 KiB
01_random_10.txt AC 68 ms 5236 KiB
01_random_11.txt AC 44 ms 5504 KiB
01_random_12.txt AC 101 ms 6516 KiB
01_random_13.txt AC 73 ms 6272 KiB
01_random_14.txt AC 93 ms 6076 KiB
02_maximum_00.txt AC 256 ms 6344 KiB
02_maximum_01.txt AC 256 ms 6296 KiB
02_maximum_02.txt AC 256 ms 6264 KiB
02_maximum_03.txt AC 254 ms 6260 KiB
02_maximum_04.txt AC 256 ms 6268 KiB
03_handmade_00.txt AC 252 ms 6420 KiB
03_handmade_01.txt AC 248 ms 6340 KiB
03_handmade_02.txt AC 250 ms 6340 KiB
03_handmade_03.txt AC 247 ms 6260 KiB
03_handmade_04.txt AC 255 ms 6316 KiB
03_handmade_05.txt AC 260 ms 6296 KiB
03_handmade_06.txt AC 251 ms 6220 KiB
03_handmade_07.txt AC 250 ms 6268 KiB
03_handmade_08.txt AC 57 ms 6352 KiB
03_handmade_09.txt AC 57 ms 6348 KiB
03_handmade_10.txt AC 255 ms 6516 KiB
03_handmade_11.txt AC 250 ms 6340 KiB
03_handmade_12.txt AC 148 ms 3560 KiB
03_handmade_13.txt AC 141 ms 3576 KiB
04_after_contest_00.txt AC 1 ms 3560 KiB