Submission #698533

# Submission time Handle Problem Language Result Execution time Memory
698533 2023-02-13T17:24:14 Z dattranxxx Match (CEOI16_match) C++11
37 / 100
4 ms 340 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1e5 + 5;
string s;
int n;

char ans[N];

int good(stack<char> st, int i) {
  for (; i <= n; ++i) {
    if (st.empty() || st.top() != s[i]) {
      st.push(s[i]);
    } else {
      st.pop();
    }
  }
  return st.empty();
}

void task1() {
  
  stack<char> st;
  for (int i = 1; i <= n; ++i) {
    if (st.empty() || st.top() != s[i]) {
      st.push(s[i]);
      ans[i] = '(';
    } else {
      
      st.push(s[i]);
      ans[i] = '(';
      if (good(st, i + 1)) continue;
      st.pop();
      ans[i] = ')';
      st.pop();
      
    }
  }
  
  if (!st.empty()) {
    cout << -1;
  } else {
    for (int i = 1; i <= n; ++i) {
      cout << ans[i];
    }
  }
  exit(0);
  
}

int main() {
  cin.tie(0)->sync_with_stdio(0); cout.tie(0);
  cin >> s;
  n = s.size();
  s = ' ' + s;
  
  if (n <= 2000) task1();
  
  
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 4 ms 340 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Incorrect 0 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -