Submission #250565

# Submission time Handle Problem Language Result Execution time Memory
250565 2020-07-18T11:14:00 Z Osama_Alkhodairy Match (CEOI16_match) C++17
37 / 100
2000 ms 1000 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
string s;

void apply(vector <char> &g, char c){
    if(g.size() > 0 && g.back() == c) g.pop_back();
    else g.push_back(c);
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    n = s.size();
    s = ';' + s;
    vector <char> cur;
    string ans(n + 1, ';');
    vector <int> r(n + 1, n);
    for(int i = 1 ; i <= n ; i++){
        if(ans[i] != ';') continue;
        vector <char> c = cur;
        int t = -1;
        for(int j = i ; j <= r[i] ; j++){
            apply(c, s[j]);
            if(c == cur && s[j] == s[i]) t = j;
        }
        if(t == -1) finish(-1);
        ans[i] = '(';
        ans[t] = ')';
        for(int j = i ; j <= t ; j++){
            r[j] = t;
        }
        apply(cur, s[i]);
    }
    cout << ans.substr(1) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 8 ms 512 KB Output is correct
9 Correct 65 ms 440 KB Output is correct
10 Correct 44 ms 384 KB Output is correct
11 Correct 73 ms 384 KB Output is correct
12 Execution timed out 2065 ms 1000 KB Time limit exceeded
13 Halted 0 ms 0 KB -