結果
| 問題 |
No.2775 Nuisance Balls
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-06-07 21:44:05 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,331 bytes |
| コンパイル時間 | 1,884 ms |
| コンパイル使用メモリ | 119,640 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-26 07:33:22 |
| 合計ジャッジ時間 | 2,878 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
using ll = long long;
constexpr int iINF = 1'000'000'000;
constexpr ll llINF = 1'000'000'000'000'000'000;
int main () {
int N; cin >> N;
// 貪欲っぽく見えるけどこういうのは注意。dpしましょ
vector<int> balls = {
1,
6,
30,
180,
360,
720,
};
vector<char> symbols = {
'.',
'o',
'R',
'S',
'M',
'C',
};
map<int, int> inv;
for (int i = 0; i < balls.size(); i++) inv[balls[i]] = i;
vector<int> dp(N + 1, iINF);
vector<int> pre(N + 1);
dp[0] = 0;
// 配る遷移でやろうね。
for (int i = 0; i < N; i++) {
for (int j = 0; j < balls.size(); j++) {
if (N < i + balls[j]) continue;
if (dp[i] + 1 < dp[i + balls[j]]) {
dp[i + balls[j]] = dp[i] + 1;
pre[i + balls[j]] = i;
}
}
}
// 復元
vector<char> ans;
int pos = N;
while (0 < pos) {
ans.push_back(inv[pos - pre[pos]]);
pos = pre[pos];
}
sort(ans.begin(), ans.end(), [&](int x, int y) { return balls[y] < balls[x]; });
for (auto i : ans) cout << symbols[i];
cout << "\n";
}