# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
571863 | FerThugGato12500 | 괄호 문자열 (CEOI16_match) | C++17 | 2089 ms | 852 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
string s, B = "";
int n;
bool poder(string A){
stack<int> lst;
int D = 0;
for(int i = 0; i < n; i++){
if(D<0) return false;
if(i<A.size()){
if(A[i]=='('){ lst.push(i); D++; }
else{
if(!lst.size() || s[lst.top()]!=s[i]) return false;
lst.pop();
D--;
}
continue;
}
if(!lst.size() || s[lst.top()]!=s[i] ){
lst.push(i);
D++;
}else{
lst.pop();
D--;
}
}
return (D==0);
}
int main(){
cin>>s;
n = s.size();
int j = 0;
while(j<n){
int ini = 0, fin = n-j;
while(ini + 1 < fin){
int mit = (ini + fin) / 2;
string c = ""; for(int i = 0; i < mit; i++) c+='(';
if(poder(B + c)){
ini = mit;
}else{
fin = mit-1;
}
}
string c = ""; for(int i = 0; i < fin; i++) c+='(';
if(poder(B + c)) ini = fin;
for(int i = 0; i < ini; i++) B+='(';
B+=')';
j += ini+1;
}
cout << (poder(B) ? B : "-1");
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... |