# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
365504 | 2021-02-11T18:38:53 Z | kostia244 | parentrises (BOI18_parentrises) | C++17 | 124 ms | 66060 KB |
#pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx,avx2,sse,sse2") #include<bits/stdc++.h> #define all(x) begin(x), end(x) using namespace std; using ll = long long; vector<vector<int>> g; string solve(string s) { g.assign(s.size(), {}); vector<int> z[2]; for(auto &i : s) { int pos = &i-&s[0]; if(i == '(') { z[0].push_back(pos); } else { if(z[0].empty()) { if(z[1].empty()) return "impossible"; g[pos].push_back(z[1].back()); g[z[1].back()].push_back(pos); z[1].pop_back(); } else { g[pos].push_back(z[0].back()); g[z[0].back()].push_back(pos); z[1].push_back(z[0].back()); z[0].pop_back(); } }/* cout << pos << ": "; for(auto i : z[0]) cout << i << " "; cout << " | "; for(auto i : z[1]) cout << i << " "; cout << endl;*/ } reverse(all(s)); z[0].clear(); for(auto &i : s) { int pos = &i-&s[0]; pos = s.size()-1-pos; if(i == ')') { if(g[pos].size() < 2) z[0].push_back(pos); } else if(g[pos].empty()) { if(z[0].empty()) return "impossible"; g[pos].push_back(z[0].back()); g[z[0].back()].push_back(pos); z[0].pop_back(); } } reverse(all(s)); vector<int> col(s.size()); for(int i = 0; i < s.size(); i++) { if(g[i].size() == 2) { int c = 1; for(auto v : g[i]) col[v] = c++; } } s = ""; for(auto i : col) { if(i == 0) s += "G"; if(i == 1) s += "B"; if(i == 2) s += "R"; } return s; } int main() { cin.tie(0)->sync_with_stdio(0); int t, x; string s; cin >> t; if(t == 1) { cin >> t; while(t--) { cin >> s; cout << solve(s) << '\n'; } } else { //calc(); cin >> t; //while(t--) cin >> x, cout << dp[x][0][0] << endl; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 2 ms | 748 KB | Output is correct |
12 | Correct | 2 ms | 1004 KB | Output is correct |
13 | Correct | 1 ms | 492 KB | Output is correct |
14 | Correct | 2 ms | 748 KB | Output is correct |
15 | Correct | 2 ms | 1004 KB | Output is correct |
16 | Correct | 5 ms | 492 KB | Output is correct |
17 | Correct | 13 ms | 7020 KB | Output is correct |
18 | Correct | 5 ms | 1260 KB | Output is correct |
19 | Correct | 10 ms | 3564 KB | Output is correct |
20 | Correct | 13 ms | 7024 KB | Output is correct |
21 | Correct | 44 ms | 2156 KB | Output is correct |
22 | Correct | 124 ms | 66056 KB | Output is correct |
23 | Correct | 49 ms | 8664 KB | Output is correct |
24 | Correct | 82 ms | 33584 KB | Output is correct |
25 | Correct | 120 ms | 66060 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Unexpected end of file - int32 expected |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Unexpected end of file - int32 expected |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 364 KB | Unexpected end of file - int32 expected |