結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
![]() |
提出日時 | 2025-05-16 21:55:32 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 968 bytes |
コンパイル時間 | 828 ms |
コンパイル使用メモリ | 103,752 KB |
実行使用メモリ | 9,728 KB |
最終ジャッジ日時 | 2025-05-17 00:26:03 |
合計ジャッジ時間 | 3,112 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 46 WA * 3 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, k; cin >> n >> k; string s; cin >> s; string ans; vector<int> id(n + 1); int pos = 0; auto dfs = [&](auto f) -> int { int cnt = 0; if (pos < n && s[pos++] == '(') { ++cnt; ans.push_back('('); int tmp = f(f); if (tmp == 0) ans += "1+1"; else if (tmp == 1) ans += "+1"; ans.push_back(')'); } else return 0; while (pos < n && s[pos++] == '(') { ++cnt; ans.push_back('+'); ans.push_back('('); int tmp = f(f); if (tmp == 0) ans += "1+1"; else if (tmp == 1) ans += "+1"; ans.push_back(')'); } return cnt; }; dfs(dfs); int sum = 0; for (auto c : ans) sum += (c == '1'); if (pos < n || sum > k) { cout << "No" << endl; } else { while (sum++ < k) ans += "+1"; cout << "Yes" << endl; cout << ans << endl; } }