# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
59580 | octopuses | 괄호 문자열 (CEOI16_match) | C++17 | 2054 ms | 1324 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Giorgi Kldiashvili
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define M 1000000007ll
using namespace std;
const int N = 100020;
int n;
char ch[N];
string a;
inline bool go(int v, stack < int > q)
{
q.push(v);
for(int i = v + 1; i <= n; ++ i)
{
if(!q.size() || a[q.top()] != a[i])
q.push(i);
else
q.pop();
}
if(q.size())
return false;
return true;
}
stack < int > q;
int main()
{
scanf("%s", &ch);
a = "$" + string(ch) + "$";
n = strlen(ch);
for(int i = 1; i <= n; ++ i)
{
if(!q.size() || a[q.top()] != a[i])
q.push(i);
else
q.pop();
}
if(q.size())
return printf("-1"), 0;
while(q.size()) q.pop();
q.push(1); printf("(");
for(int i = 2; i <= n; ++ i)
{
if(!q.size() || a[q.top()] != a[i])
q.push(i), printf("(");
else
{
if(go(i, q))
q.push(i), printf("(");
else
q.pop(), printf(")");
}
}
}
컴파일 시 표준 에러 (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... |