結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
eve__fuyuki
|
| 提出日時 | 2025-05-26 18:04:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 822 bytes |
| コンパイル時間 | 2,245 ms |
| コンパイル使用メモリ | 193,820 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-05-26 18:04:42 |
| 合計ジャッジ時間 | 5,305 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
void fast_io() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
}
int main() {
fast_io();
int n, k;
cin >> n >> k;
string s;
cin >> s;
int cnt = 0;
for (char c : s) {
if (c == '(') {
cnt++;
} else {
cnt--;
}
if (cnt < 0) {
cout << "No" << endl;
return 0;
}
}
if (cnt != 0) {
cout << "No" << endl;
return 0;
}
string ans = "";
int cur = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
if (i && s[i - 1] != '(') {
ans += "+";
}
ans += '(';
} else if (ans.back() == '(') {
ans += "1+1)";
cur += 2;
} else {
ans += "+1)";
cur += 1;
}
}
if (cur > k) {
cout << "No" << endl;
return 0;
}
cout << "Yes" << endl;
for (int i = 0; i < k - cur; i++) {
ans += "+1";
}
cout << ans << "\n";
}
eve__fuyuki