結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
sai
|
| 提出日時 | 2025-05-16 22:24:40 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,230 bytes |
| コンパイル時間 | 3,371 ms |
| コンパイル使用メモリ | 278,768 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-05-17 00:31:38 |
| 合計ジャッジ時間 | 8,581 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 WA * 29 |
ソースコード
#include <bits/stdc++.h>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
std::string s;
std::cin >> n >> k >> s;
int Min = 0;
int cnt = 0, Max = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
cnt++;
Max++;
} else {
if (cnt == 0) {
std::cout << "No\n";
return 0;
}
cnt--;
if (cnt == 0) {
Min += Max + 1;
Max = 0;
}
}
}
if (cnt > 0 || Min > k) {
std::cout << "No\n";
return 0;
}
std::cout << "Yes\n";
std::vector<int> Pair(n, -1), st;
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
st.push_back(i);
} else {
assert(st.size());
Pair[st.back()] = i;
Pair[i] = st.back();
st.pop_back();
}
}
assert(st.empty());
std::string ans = "";
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
if (i > 0 && s[i - 1] == ')') {
ans += '+';
}
ans += '(';
if (Pair[i] == i + 1) {
ans += "1+1";
}
if (s.substr(i + 1, 2) == "()") {
ans += "1+";
}
} else {
ans += ')';
}
}
for (int i = k - Min; i--;) {
ans += "+1";
}
std::cout << ans << '\n';
}
sai