結果
| 問題 | No.3764 Graduation Live |
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2026-10-07 23:24:06 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
TLE
不安定
|
| 実行時間 | - |
| コード長 | 2,450 bytes |
| 記録 | |
| コンパイル時間 | 2,786 ms |
| コンパイル使用メモリ | 368,956 KB |
| 実行使用メモリ | 9,844 KB |
| 最終ジャッジ日時 | 2026-10-09 20:54:21 |
| 合計ジャッジ時間 | 11,358 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 TLE * 1 -- * 32 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// Approximate solver: a finite beam does not guarantee the optimal X_c (or C).
constexpr int BEAM_WIDTH = 256;
constexpr int PERSON[6][2] = {{0, -1}, {1, -1}, {2, -1},
{0, 1}, {0, 2}, {1, 2}};
struct State {
array<int, 6> count{};
array<int, 3> used{};
ll score = 0;
};
void solve() {
int n;
array<int, 3> stamina;
cin >> n >> stamina[0] >> stamina[1] >> stamina[2];
array<vector<ll>, 6> value;
for (int i = 0; i < n; ++i) {
int type;
ll score;
cin >> type >> score;
value[type - 1].push_back(score);
}
for (auto &a : value) sort(a.rbegin(), a.rend());
vector<State> beam(1);
vector<ll> answer;
for (int depth = 1; depth <= n; ++depth) {
vector<State> candidates;
candidates.reserve(beam.size() * 6);
for (const State &s : beam) {
for (int t = 0; t < 6; ++t) {
if (s.count[t] == (int)value[t].size()) continue;
int a = PERSON[t][0], b = PERSON[t][1];
if (s.used[a] == stamina[a] ||
(b != -1 && s.used[b] == stamina[b])) continue;
State next = s;
next.score += value[t][next.count[t]++];
++next.used[a];
if (b != -1) ++next.used[b];
candidates.push_back(next);
}
}
if (candidates.empty()) break;
// Different orders of choosing the same six prefixes are one state.
sort(candidates.begin(), candidates.end(), [](const State &a, const State &b) {
return a.count < b.count;
});
candidates.erase(unique(candidates.begin(), candidates.end(),
[](const State &a, const State &b) {
return a.count == b.count;
}), candidates.end());
const int keep = min<int>(BEAM_WIDTH, candidates.size());
partial_sort(candidates.begin(), candidates.begin() + keep, candidates.end(),
[](const State &a, const State &b) {
if (a.score != b.score) return a.score > b.score;
return a.count < b.count;
});
candidates.resize(keep);
answer.push_back(candidates.front().score);
beam = move(candidates);
}
cout << answer.size();
for (ll x : answer) cout << ' ' << x;
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int test_cases;
cin >> test_cases;
while (test_cases--) solve();
}
ei1333333