# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
930265 | 2024-02-19T08:30:20 Z | ttamx | Match (CEOI16_match) | C++14 | 6 ms | 12892 KB |
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; int n; int dp[N][30]; string t,ans; stack<char> s; void solve(int l,int r){ if(l>r)return; int m=dp[r][t[l]]; ans[m]=')'; solve(l+1,m-1); solve(m+1,r); } int main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> t; for(auto &x:t){ if(!s.empty()&&x==s.top())s.pop(); else s.emplace(x); x-='a'; } if(!s.empty())cout << -1,exit(0); n=t.size(); ans.assign(n,'('); for(int i=1;i<n;i++){ int p=dp[i-1][t[i]]-1; if(p>0)for(int j=0;j<26;j++){ dp[i][j]=t[p]==j?p:dp[p][j]; } dp[i][t[i]]=i; } solve(0,n-1); cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 500 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 500 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2652 KB | Output is correct |
8 | Correct | 1 ms | 2652 KB | Output is correct |
9 | Correct | 1 ms | 2696 KB | Output is correct |
10 | Correct | 1 ms | 2652 KB | Output is correct |
11 | Correct | 1 ms | 2652 KB | Output is correct |
12 | Correct | 3 ms | 9308 KB | Output is correct |
13 | Correct | 5 ms | 9308 KB | Output is correct |
14 | Correct | 4 ms | 9308 KB | Output is correct |
15 | Correct | 5 ms | 11612 KB | Output is correct |
16 | Correct | 5 ms | 11612 KB | Output is correct |
17 | Correct | 5 ms | 11612 KB | Output is correct |
18 | Correct | 6 ms | 11356 KB | Output is correct |
19 | Correct | 5 ms | 12100 KB | Output is correct |
20 | Correct | 5 ms | 9560 KB | Output is correct |
21 | Correct | 6 ms | 12892 KB | Output is correct |