Submission #1117712

# Submission time Handle Problem Language Result Execution time Memory
1117712 2024-11-24T07:45:21 Z vjudge1 Match (CEOI16_match) C++17
10 / 100
1231 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    string s, ans = ")";
    cin>>s;
    int n = s.size();
    for (int i = (1<<n) - 1; i >= 0; i--){
        deque<int> de;
        int pr = 0, can = 1;
        for (int j = 0; j < n; j++){
            int val = i & (1<<j);
            if (val != 0) val = -1;
            else val = 1;
            pr += val;
            if (pr < 0){
                can = 0;
                break;
            }
        }
        for (int j = 0; j < n; j++){
            int val = i & (1<<j);
            if (val != 0) val = -1;
            else val = 1;
            pr += val;
            if (pr < 0){
                can = 0;
                break;
            }
        }
        for (int j = 0; j < n; j++){
            if (!can) break;
            int val = i & (1<<j);
            if (val == 0){
                de.push_back(j);
            }
            else{
                if (s[de.back()] != s[j]){
                    can = 0;
                    break;
                }
                de.pop_back();
            }
        }
        if (de.size() != 0) can = 0;
        if (can){
            string cmp;
            for (int j = 0; j < n; j++){
                if (!can) break;
                int val = i & (1<<j);
                if (val == 0){
                    cmp += '(';
                }
                else{
                    cmp += ')';
                }
            }
            ans = min(ans, cmp);
        }
    }
    if (ans == ")"){
        cout<<-1;
    }
    else{
        cout<<ans;
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 13 ms 336 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 13 ms 336 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
4 Incorrect 1231 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 13 ms 336 KB Output is correct
3 Correct 4 ms 336 KB Output is correct
4 Incorrect 1231 ms 336 KB Output isn't correct
5 Halted 0 ms 0 KB -