結果
| 問題 |
No.2947 Sing a Song
|
| コンテスト | |
| ユーザー |
zawakasu
|
| 提出日時 | 2024-10-25 21:40:45 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 2,000 ms |
| コード長 | 1,252 bytes |
| コンパイル時間 | 1,758 ms |
| コンパイル使用メモリ | 81,712 KB |
| 最終ジャッジ日時 | 2025-02-24 22:56:59 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <iostream>
#include <iomanip>
#include <cassert>
#include <string>
#include <vector>
int main() {
std::cin.tie(nullptr)->sync_with_stdio(false);
int N;
std::string S, T;
std::cin >> N >> S >> T;
const int MAX{200010};
std::vector<int> dp(MAX, -1);
dp[0] = 0;
for (int i{} ; i < MAX ; i++) {
if (dp[i] == -1) continue;
if (i + (int)S.size() < MAX and dp[i + S.size()] < dp[i] + 1) {
dp[i + S.size()] = dp[i] + 1;
}
if (i + (int)T.size() < MAX and dp[i + T.size()] < dp[i]) {
dp[i + T.size()] = dp[i];
}
}
auto get{[&](int x) -> std::vector<std::string> {
std::vector<std::string> res;
assert(dp[x] != -1);
for (int i{} ; i < dp[x] ; i++) res.push_back(S);
int remain{x - dp[x] * (int)S.size()};
assert(remain >= 0 and remain % (int)T.size() == 0);
while (remain) {
res.push_back(T);
remain -= (int)T.size();
}
return res;
}};
for (int i{} ; i < N ; i++) {
int A;
std::cin >> A;
auto res{get(A)};
for (int j{} ; j < (int)res.size() ; j++) std::cout << res[j] << (j + 1 == (int)res.size() ? '\n' : ' ');
}
}
zawakasu