結果
問題 |
No.3143 Colorless Green Parentheses Sleep Furiously
|
ユーザー |
|
提出日時 | 2025-05-16 22:04:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,601 bytes |
コンパイル時間 | 1,983 ms |
コンパイル使用メモリ | 198,780 KB |
実行使用メモリ | 6,272 KB |
最終ジャッジ日時 | 2025-05-17 00:28:05 |
合計ジャッジ時間 | 6,339 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 WA * 10 RE * 3 |
ソースコード
#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ int main(){ ll n,k; cin>>n>>k; string s; cin>>s; ll score=calc_min(s); if(score>k) { no(); return 0; } else { string ans=""; int cur=0; rep(i,n) { if(s[i]=='(') { if(ans.size()>0) { if(ans.back()==')') ans+='+'; } ans+="(1+"; cur++; } else { if(ans.back()==')') { ans+=")"; } else { ans+="1)"; cur++; } } } ans.pop_back(); while(cur<k) { cur++; ans+="+1"; } ans+=')'; yes(); cout<<ans<<nl; } } /////// library zone /////// #else #include <bits/stdc++.h> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define irep(i,r,l) for(ll i=r;i>=l;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> int calc_min(string &s) { stack<int> st; for(char c:s) { if(c=='(') { st.push(0); } else { int cur=st.top(); st.pop(); int score=(cur==0 ? 2 : cur+1); if(st.empty()) { st.push(score); } else { int prev=st.top(); st.pop(); st.push(prev+score); } } } return st.empty() ? 0:st.top(); } 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; } ll modpow(ll fl, ll po, ll mode) { // mode: 0=modなし, 1=modあり ll ret=1; if (mode) { while (po>0) { if (po&1) ret=(ret*fl)%mod; fl=(fl*fl)%mod; po>>=1; } } else { while (po>0) { if(po&1) ret*=fl; fl*=fl; po>>=1; } } return ret; } #endif