제출 #1143747

#제출 시각아이디문제언어결과실행 시간메모리
1143747mnbvcxz123Match (CEOI16_match)C++20
0 / 100
0 ms320 KiB
#include<bits/stdc++.h> using namespace std; using ll=long long; constexpr int N=1e5+5; string s; ll n,dp[N][26]; string f(ll l, ll r){ if(l>r)return ""; return '('+f(l+1,dp[r][s[l]-'a']-1)+')'+f(dp[r][s[l]-'a']+1,r); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>s; n=s.size(); s='0'+s; stack<ll>S; for(int i=1;i<=n;++i){ if(!S.empty() and S.top()==s[i])S.pop(); else S.push(s[i]); } if(!S.empty()){ cout<<-1<<'\n'; return 0; } for (ll i = 2; i <= n; i++) for (ll j = 0; j < 26; j++) if (j + 'a' == s[i]) dp[i][j] = i; else dp[i][j] = dp[i - 1][s[i] - 'a'] - 1 < 0 ? 0 : dp[dp[i - 1][s[i] - 'a'] - 1][j]; for(int i=0;i<2;++i){ for(int j=1;j<=n;++j) cout<<dp[j][i]<<' '; cout<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...