Submission #740985

# Submission time Handle Problem Language Result Execution time Memory
740985 2023-05-13T10:55:43 Z 이동현(#9959) Match (CEOI16_match) C++17
37 / 100
2000 ms 1032 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(n, '(');
    vector<int> chk(n);
    for(int i = 0; i < n; ++i){
        if(chk[i]){
            continue;
        }
        vector<char> stk;
        int lst = -1;
        for(int j = i + 1; j < n && !chk[j]; ++j){
            if(!(int)stk.size() && s[i] == s[j]){
                lst = j;
            }
            if((int)stk.size() && stk.back() == s[j]){
                stk.pop_back();
            }
            else{
                stk.push_back(s[j]);
            }
        }
        if(lst == -1){
            cout << "-1\n";
            return 0;
        }

        ans[i] = '(';
        ans[lst] = ')';
        chk[i] = chk[lst] = 1;
    }

    cout << ans << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 3 ms 336 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Correct 4 ms 340 KB Output is correct
9 Correct 33 ms 340 KB Output is correct
10 Correct 24 ms 388 KB Output is correct
11 Correct 44 ms 340 KB Output is correct
12 Correct 1915 ms 1032 KB Output is correct
13 Execution timed out 2065 ms 980 KB Time limit exceeded
14 Halted 0 ms 0 KB -