# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
874930 | 2023-11-18T06:26:34 Z | Faisal_Saqib | Match (CEOI16_match) | C++17 | 0 ms | 348 KB |
#include <bits/stdc++.h> using namespace std; bool valid(string& s,string& b) { int n=s.size(); vector<int> cp; for(int i=0;i<n;i++) { if(b[i]=='?') return 0; if(b[i]=='(') { cp.push_back(i); } else if(cp.size()==0) return 0; else if(s[cp.back()]!=s[i]) return 0; else cp.pop_back(); } return (cp.size()==0); } int main() { string s; cin>>s; int n=s.size(); string ans((size_t)n,')'); vector<int> cp1[26]; vector<int> cp; for(int j=0;j<n;j++) { string cur=ans; for(int i=0;i<n;i++) { if(i==j) { cp1[s[i]-'a'].push_back(i); continue; } if(cp1[s[i]-'a'].size()) { cur[cp1[s[i]-'a'].back()]='('; cur[i]=')'; cp1[s[i]-'a'].pop_back(); } else cp1[s[i]-'a'].push_back(i); } if(valid(s,cur)) ans=min(ans,cur); } if(ans[0]=')') ans="-1"; cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |