結果
| 問題 | No.873 バイナリ、ヤバいなり!w |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-08 00:31:38 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,254 bytes |
| 記録 | |
| コンパイル時間 | 3,051 ms |
| コンパイル使用メモリ | 352,840 KB |
| 実行使用メモリ | 9,928 KB |
| 最終ジャッジ日時 | 2026-10-08 00:31:46 |
| 合計ジャッジ時間 | 5,846 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 36 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int targetScore;
cin >> targetScore;
// minEvents[score] = minimum playback events needed for this score.
const int INF = 1e9;
vector<int> minEvents(targetScore + 1, INF);
minEvents[0] = 0;
for (int score = 1; score <= targetScore; score++) {
for (int length = 1; length * length <= score; length++) {
minEvents[score] = min(
minEvents[score],
length + minEvents[score - length * length]
);
}
}
string trace;
int remainingScore = targetScore;
char startPath = 'L';
while (remainingScore > 0) {
int shortestEndingL = -1;
int longestValidLength = -1;
for (int length = 1;
length * length <= remainingScore;
length++) {
// Only consider blocks that preserve minimum total length.
if (length + minEvents[remainingScore - length * length]
!= minEvents[remainingScore]) {
continue;
}
// Lengths are visited in increasing order.
longestValidLength = length;
char endPath;
if (length % 2 == 1) {
endPath = startPath;
} else {
endPath = (startPath == 'L') ? 'G' : 'L';
}
// Keep the first, hence shortest, valid block ending in L.
if (endPath == 'L' && shortestEndingL == -1) {
shortestEndingL = length;
}
}
int chosenLength;
if (shortestEndingL != -1) {
chosenLength = shortestEndingL;
} else {
chosenLength = longestValidLength;
}
// Append the chosen alternating block.
char currentPath = startPath;
for (int i = 0; i < chosenLength; i++) {
trace.push_back(currentPath);
currentPath = (currentPath == 'L') ? 'G' : 'L';
}
remainingScore -= chosenLength * chosenLength;
// Repeating the previous ending path creates a block boundary.
startPath = trace.back();
}
cout << trace << '\n';
}