Submission #740908

# Submission time Handle Problem Language Result Execution time Memory
740908 2023-05-13T08:48:09 Z 이동현(#9959) Match (CEOI16_match) C++17
37 / 100
2000 ms 864 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int n = (int)s.size();
    string ans;
    vector<char> stk;
    for(int i = 0; i < n; ++i){
        stk.push_back(s[i]);

        auto nstk = stk;
        for(int j = i + 1; j < n; ++j){
            if((int)nstk.size() && nstk.back() == s[j]){
                nstk.pop_back();
            }
            else{
                nstk.push_back(s[j]);
            }
        }
        if(!(int)nstk.size()){
            ans += '(';
        }
        else{
            stk.pop_back();
            if(!(int)stk.size() || stk.back() != s[i]){
                cout << "-1\n";
                return 0;
            }
            stk.pop_back();
            ans += ')';
        }
    }

    cout << ans << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 3 ms 340 KB Output is correct
7 Correct 4 ms 340 KB Output is correct
8 Correct 49 ms 340 KB Output is correct
9 Correct 57 ms 364 KB Output is correct
10 Correct 55 ms 340 KB Output is correct
11 Correct 58 ms 384 KB Output is correct
12 Execution timed out 2037 ms 864 KB Time limit exceeded
13 Halted 0 ms 0 KB -