結果
| 問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
| コンテスト | |
| ユーザー |
Cecil
|
| 提出日時 | 2025-05-16 23:16:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,800 bytes |
| コンパイル時間 | 1,809 ms |
| コンパイル使用メモリ | 197,928 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-05-17 00:35:51 |
| 合計ジャッジ時間 | 4,107 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 47 WA * 2 |
ソースコード
#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;
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('+');
} 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++){
ans.push_back('+');
ans.push_back('1');
}
cout << "Yes" << endl;
for (int i = 0; i < (int)ans.size(); i++) {
cout << ans[i];
}
cout << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
Cecil