# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1168966 | mmmmge1234 | Match (CEOI16_match) | C++20 | 50 ms | 28228 KiB |
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
string s;
long long dp[100005][26];
string solve(long long l, long long r){
if(l > r) return "";
return '(' + solve(l + 1, dp[r][s[l] - 'a'] - 1) + ')' + solve(dp[r][s[l] - 'a'] + 1, r);
}
int main(){
if(fopen("stop.inp" , "r")){
freopen("stop.inp", "r", stdin);
freopen("stop.out", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
cout.tie(0)->sync_with_stdio(0);
cin >> s;
long long n = (long long)s.size();
s = '0' + s;
stack<long long> st;
for(long long i = 1; i <= n; i++){
if(!st.empty() && st.top() == s[i]) st.pop();
else st.push(s[i]);
}
if(!st.empty()){
cout << -1 << '\n';
return 0;
}
for(long long i = 2; i <= n; i++){
for(long long 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];
}
}
cout << solve(1, n) << '\n';
return 0;
}
//I hate every single person in and not in this room, farewell.
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |