結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
|
提出日時 | 2025-05-16 21:47:09 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,662 bytes |
コンパイル時間 | 3,770 ms |
コンパイル使用メモリ | 276,728 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-17 00:24:34 |
合計ジャッジ時間 | 5,532 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 44 WA * 5 |
ソースコード
#include <bits/stdc++.h> //#include "atcoder/fenwicktree" using namespace std; typedef long long ll; const int INF = 1<<30; const ll INFLL = 1LL<<60; const ll MOD = 998244353; const double INFD = 1.0E18; const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, -1, 0, 1}; //const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; //const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using Pair = pair<ll, ll>; using Graph = vector<vector<pair<int, int>>>; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int n, k; cin >> n >> k; string s; cin >> s; //最低の値、n/2葉 bool ok = true; int cnt = 0; int m = n / 2; for (int i = 0; i < n; i++){ if (s[i] == '(') cnt++; else cnt--; if (cnt < 0) ok = false; if (i > 0 && s[i - 1] == '(' && s[i] == ')') m++; } if (cnt != 0) ok = false; if (k < m) ok = false; cout << (ok ? "Yes" : "No") << endl; if (ok){ bool begin = true; string ans; for (int i = 0; i < n; i++){ if (s[i] == '(') ans += "("; else{ if (i > 0 && s[i - 1] == '('){ ans += "1+1"; if (begin){ for (int j = 0; j < k - m; j++){ ans += "+1"; } begin = false; } } else{ ans += "1"; } ans += ")"; if (i != n - 1) ans += "+"; } } cout << ans << endl; } return 0; }