| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 390724 | Vladth11 | 괄호 문자열 (CEOI16_match) | C++14 | 11 ms | 12248 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debug_with_space(x) cerr << #x << " " << x << " "
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;
const ll NMAX = 100001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 225;
const ll base = 31;
const ll nr_of_bits = 21;
int previous[NMAX][28];
string rez;
string s;
vector <int> v[28];
void solve(int l, int r) {
int pz;
if(l > r)
return;
if(s[l] == s[r]) {
rez[l] = '(';
rez[r] = ')';
solve(l + 1, r - 1);
return;
}
int last = previous[r][s[l] - 'a' + 1];
rez[last] = ')';
rez[l] = '(';
solve(l + 1, last - 1);
solve(last + 1, r);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
rez = s;
stack <pii> st;
for(ll i = 0; i < s.size(); i++) {
ll c = s[i] - 'a' + 1;
if(st.size() && st.top().first == c) {
st.pop();
} else {
st.push({c, i});
}
int cn = 0;
if(i > 0)
cn = previous[i - 1][c];
if(cn != 0) {
for(int j = 1; j <= 26; j++) {
previous[i][j] = previous[cn - 1][j];
}
}
previous[i][c] = i;
}
///cum calculez pe previous[i][j] = x - de la x + 1...i e ok parantezarea, x e maxim si s[x] = j
if(st.size()) {
cout << -1;
return 0;
}
solve(0, s.size() - 1);
cout << rez;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
