# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1117790 | vjudge1 | Match (CEOI16_match) | C++17 | 368 ms | 504 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define in insert
#define fi first
#define se second
#define vl vector<ll>
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int sz = 1e5 + 123; /// mind this
const int MAX = 2e6 + 123;
const int BS = 61;
const ll inf = 1e17;
const int mod = 998244353;
void solve(){
string s;
cin >> s;
ll n = s.size(), i, j, k;
ll cost[2] = {1, -1};
string ans;
for(i = 0; i < (1 << n); i++){
bool valid = true;
ll res = 0;
for(j = n - 1; j >= 0; j--){
if(i & (1 << j)){
res --;
}
else{
res ++;
}
if(res < 0){
valid = false;
break;
}
}
if(res != 0){valid = false;}
if(!valid){continue;}
bool ok = 1;
for(j = n - 1; j >= 0; j--){
res = 0;
valid = true;
if((i & (1 << j))){continue;}
for(k = j; k >= 0; k--){
if(i & (1 << k)){
res --;
}
else{
res ++;
}
if(res < 1){
if((res == 0) && (i & (1 << k))){
ok &= (s[n - j - 1] == s[n - k - 1]);
if(!ok){
break;
}
}
valid = false;
break;
}
}
if(!ok){break;}
}
if(!ok){continue;}
break;
}
if(i == (1 << n)){
cout << -1 << endl;
return ;
}
// cout << i << endl;
for(j = n - 1; j >= 0; j--){
if(i & (1 << j)){
ans += ')';
}
else{
ans += '(';
}
}
cout << ans << endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
// cin >> t;
while(t--){
solve();
}
}
/*
10 10
10 10 10 10 10 10 10 10 10 10
1 2
2 4
5 2
6 3
3 1
6 7
9 7
8 6
8 10
*/
컴파일 시 표준 에러 (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... |