結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
Cecil
|
| 提出日時 | 2025-05-16 23:38:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 2,015 bytes |
| コンパイル時間 | 1,952 ms |
| コンパイル使用メモリ | 196,348 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2025-05-17 00:37:04 |
| 合計ジャッジ時間 | 4,549 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 WA * 1 |
ソースコード
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){
int N,K;
string S;
cin >> N >> K;
cin >> S;
if (N%2!=0){
cout << "No" << endl;
return 0;
}
vector<char> stack;
for (int i=0; i<N; i++){
if (stack.size()>0 && stack.back()=='(' && S[i]==')'){
stack.pop_back();
} else {
stack.push_back(S[i]);
}
}
if (!stack.empty()){
cout << "No" << endl;
} else {
int cnt=0;
for (int i=0; i<N-1; i++){
if (S[i]=='(' && S[i+1]==')'){
cnt++;
}
}
if (cnt*2+(N/2-cnt)<=K){
vector<char> ans;
bool ok = false;
for (int i=0; i<N-1; i++){
if (S[i]=='(' && S[i+1]==')'){
ans.push_back('(');
ans.push_back('1');
ans.push_back('+');
ans.push_back('1');
K -= 2;
} else if (S[i]==')' && S[i+1]=='('){
ans.push_back(S[i]);
ans.push_back('+');
ok = true;
} else if (S[i]=='('){
ans.push_back(S[i]);
} else {
ans.push_back(S[i]);
ans.push_back('+');
ans.push_back('1');
K -= 1;
}
}
ans.push_back(S.back());
for (int i=0; i<K; i++){
ok = true;
ans.push_back('+');
ans.push_back('1');
}
if (ok){
cout << "Yes" << endl;
for (int i = 0; i < (int)ans.size(); i++) {
cout << ans[i];
}
cout << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
}
}
return 0;
}
Cecil