Submission #153419

# Submission time Handle Problem Language Result Execution time Memory
153419 2019-09-14T07:08:53 Z lyc Match (CEOI16_match) C++14
37 / 100
2000 ms 528 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    string S; cin >> S;
    int N = S.length();
    string T = "";
    stack<char> stk;
    FOR(i,0,N-1) if (stk.empty() || stk.top() != S[i]) stk.push(S[i]); else stk.pop();
    if (!stk.empty()) { cout << -1 << '\n'; }
    else {
        FOR(i,0,N-1) {
            int M = (int)T.length();
            FOR(j,0,M-1) if (T[j] == '(') stk.push(S[j]); else stk.pop();

            stk.push(S[i]);
            //cout << i << " i stk " << stk.size() << " :: " << T << endl;
            FOR(j,M+1,N-1) if (stk.empty() || stk.top() != S[j]) stk.push(S[j]); else stk.pop();
            T += (stk.empty() ? '(' : ')');

            while (!stk.empty()) stk.pop();
        }
        cout << T << '\n';
    }
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 9 ms 376 KB Output is correct
7 Correct 15 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 9 ms 376 KB Output is correct
7 Correct 15 ms 376 KB Output is correct
8 Correct 237 ms 528 KB Output is correct
9 Correct 258 ms 504 KB Output is correct
10 Correct 185 ms 504 KB Output is correct
11 Correct 164 ms 440 KB Output is correct
12 Execution timed out 2053 ms 504 KB Time limit exceeded
13 Halted 0 ms 0 KB -