提出 #3827541
ソースコード 拡げる
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;
const LL inf = 112345678901234567;
LL N;
std::vector<LL>x, c, v;
std::vector<std::vector<LL>>memo1, memo2;
LL dp1(LL b, LL i)
{
if (memo1[b][i] != -1) return memo1[b][i];
LL csum = 0, vsum = 0;
rep(j, N)
{
if (b&(1LL << j))
{
csum += c[j];
vsum += v[j];
}
}
if (csum <= x[i]) return memo1[b][i] = vsum;
LL res = 0;
rep(j, N)
{
if (b&(1LL << j)) res = std::max(res, dp1(b ^ (1LL << j), i));
}
return memo1[b][i] = res;
}
LL dp2(LL b, LL i)
{
if (i == N) return 0;
if (i > N) return -inf;
if (memo2[b][i] != -1) return memo2[b][i];
LL res1 = inf;
rep(j, N) if (b&(1LL << j)) res1 = std::min(res1, dp2(b ^ (1LL << j), i + 1));
LL res2 = dp1(b, i);
return memo2[b][i] = std::max(res1, res2);
}
int main()
{
in >> N;
x.resize(N + 1); c.resize(N); v.resize(N);
rep(i, N) in >> x[i + 1];
rep(i, N) in >> c[i];
rep(i, N) in >> v[i];
rep(i, N) x[i + 1] += x[i];
memo1.resize((1LL << N));
rep(i, memo1.size()) memo1[i].resize(N + 1, -1);
memo2.resize((1LL << N));
rep(i, memo2.size()) memo2[i].resize(N + 1, -1);
out << dp2((1LL << N) - 1, 0) << std::endl;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - 駆引取引 |
| ユーザ | babcs2035 |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 500 |
| コード長 | 1285 Byte |
| 結果 | AC |
| 実行時間 | 737 ms |
| メモリ | 94464 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt |
| All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 00_example_04.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00_example_01.txt | AC | 1 ms | 256 KiB |
| 00_example_02.txt | AC | 1 ms | 256 KiB |
| 00_example_03.txt | AC | 1 ms | 256 KiB |
| 00_example_04.txt | AC | 633 ms | 94464 KiB |
| 01.txt | AC | 1 ms | 256 KiB |
| 02.txt | AC | 278 ms | 47360 KiB |
| 03.txt | AC | 526 ms | 94464 KiB |
| 04.txt | AC | 119 ms | 21760 KiB |
| 05.txt | AC | 1 ms | 256 KiB |
| 06.txt | AC | 21 ms | 5120 KiB |
| 07.txt | AC | 1 ms | 256 KiB |
| 08.txt | AC | 265 ms | 47360 KiB |
| 09.txt | AC | 609 ms | 94464 KiB |
| 10.txt | AC | 113 ms | 21760 KiB |
| 11.txt | AC | 612 ms | 94464 KiB |
| 12.txt | AC | 609 ms | 94464 KiB |
| 13.txt | AC | 653 ms | 94464 KiB |
| 14.txt | AC | 626 ms | 94464 KiB |
| 15.txt | AC | 666 ms | 94464 KiB |
| 16.txt | AC | 610 ms | 94464 KiB |
| 17.txt | AC | 615 ms | 94464 KiB |
| 18.txt | AC | 625 ms | 94464 KiB |
| 19.txt | AC | 577 ms | 94464 KiB |
| 20.txt | AC | 668 ms | 94464 KiB |
| 21.txt | AC | 677 ms | 94464 KiB |
| 22.txt | AC | 5 ms | 1280 KiB |
| 23.txt | AC | 1 ms | 256 KiB |
| 24.txt | AC | 674 ms | 94464 KiB |
| 25.txt | AC | 638 ms | 94464 KiB |
| 26.txt | AC | 624 ms | 94464 KiB |
| 27.txt | AC | 1 ms | 256 KiB |
| 28.txt | AC | 312 ms | 47360 KiB |
| 29.txt | AC | 737 ms | 94464 KiB |
| 30.txt | AC | 693 ms | 94464 KiB |
| 31.txt | AC | 640 ms | 94464 KiB |
| 32.txt | AC | 631 ms | 94464 KiB |
| 33.txt | AC | 626 ms | 94464 KiB |
| 34.txt | AC | 683 ms | 94464 KiB |
| 35.txt | AC | 617 ms | 94464 KiB |
| 36.txt | AC | 5 ms | 1280 KiB |
| 37.txt | AC | 10 ms | 2688 KiB |
| 38.txt | AC | 2 ms | 512 KiB |
| 39.txt | AC | 672 ms | 94464 KiB |