結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
|
提出日時 | 2025-05-16 23:29:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,266 bytes |
コンパイル時間 | 2,010 ms |
コンパイル使用メモリ | 201,144 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-17 00:36:40 |
合計ジャッジ時間 | 4,662 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 48 WA * 1 |
ソースコード
#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ int main(){ ll n,k; cin>>n>>k; string s; cin>>s; if(s=="()" && k==2) { no(); return 0; } if(!taio(s)){ no(); return 0; } ll mn=calc_min(s); if(mn>k){ no(); return 0; } ll cur=mn; string ans; ans.reserve(n*4+(k-mn)*3); bool prev=false; rep(i,n){ if(s[i]=='('){ if(prev) ans.push_back('+'); ans+="(1+"; prev=false; } else { if(prev){ ans.push_back(')'); } else { ans+="1)"; } prev=true; } } while(cur<k){ ans+="+1"; cur++; } yes(); cout<<ans<<"\n"; return 0; } /////// library zone /////// #else #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define srep(i,l,r) for(ll i=l;i<=r;i++) using ll = long long; using ld = long double; const ll mod=998244353; #define vout(v) for(auto i :v) cout<<i<<" "; #define INF 9223300000000000000ll #define Winf 5e12 #define nl "\n" #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define vl vector<ll> #define vc vector<char> ll calc_min(const string &s){ stack<ll> st; for(char c:s){ if(c=='('){ st.push(0); } else { ll cur=st.top(); st.pop(); ll sc=(cur==0 ? 2 : cur+1); if(st.empty()) st.push(sc); else{ ll t=st.top(); st.pop(); st.push(t+sc); } } } return st.empty()?0:st.top(); } bool taio(const string &s){ ll bal=0; for(char c:s){ if(c=='(') bal++; else{ if(bal==0) return false; bal--; } } return bal==0; } template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} void no() { cout<<"No"<<nl;} void yes() { cout<<"Yes"<<nl;} void yn(bool a) { cout<<(a ? "Yes":"No")<<nl; } ll sum(vector<ll>& a) { ll ans=0; for(auto i:a) ans+=i; return ans; } #endif