# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874901 | 2023-11-18T05:00:21 Z | Sir_Ahmed_Imran | Match (CEOI16_match) | C++17 | 0 ms | 2396 KB |
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define li long int #define ld long double #define append push_back #define add insert #define nl "\n" #define ff first #define ss second #define pii pair<int,int> #define pic pair<int,char> #define all(x) (x).begin(),(x).end() #define sum(a) accumulate(all(a),0) #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL) #define terminator main #define N 20001 int dp[N][N]; void solve(){ string a; int n,m,o,p,q,r; cin>>a; n=a.size(); for(int i=0;i<n;i++) for(int j=0;j<n;j++) dp[i][j]=0; for(int j=1;j<n;j++){ for(int i=0;i<n-j;i++){ dp[i][i+j]=(a[i]==a[i+j] && (dp[i+1][i+j-1] || j==1)); for(int k=i+2;k<i+j;k++) dp[i][i+j]|=(dp[i][k-1] && dp[k][i+j]); } } if(!dp[0][n-1]){ cout<<-1; return; } for(int i=0;i<n;i++){ o=0; for(int j=i+1;j<n;j++){ if((dp[i+1][j-1] || j-i==1) && a[i]==a[j] && a[i]!=')') o=j; } if(o){ a[i]='('; a[o]=')'; } else a[i]=')'; cout<<a[i]; } } int terminator(){ L0TA; solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2396 KB | Output is correct |
2 | Incorrect | 0 ms | 2396 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |