답안 #64213

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64213 2018-08-03T13:49:03 Z Talant parentrises (BOI18_parentrises) C++17
22 / 100
178 ms 6556 KB
#include <bits/stdc++.h>

#define mk make_pair
#define sc second
#define fr first
#define pb emplace_back
#define all(s) s.begin(), s.end()
#define sz(s) ( (int)s.size() )
#define Scan(a) scanf ("%I64d", &a)
#define scan(a) scanf ("%d", &a)

using namespace std;

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

int t,k,n;
int b[N],blc[N];
char ans[N];

string a;

main () {
      cin >> k;
      cin >> t;

      while (t --) {
            int flag = 0;
            cin >> a;

            n = a.size();

            for (int i = 0; i <= n; i ++) b[i] = blc[i] = 0,ans[i] = '0';

            for (int i = 0; i < a.size(); i ++) {
                  if (i > 0) b[i] = b[i - 1];
                  b[i] = max(0,b[i]);

                  if (a[i] == '(') b[i] ++;
                  else b[i] --;
                  if (b[i] < 0) ans[i] = 'B';
            }
            for (int i = n - 1; i >= 0; i --) {
                  if (i < n - 1) blc[i] = blc[i + 1];
                  blc[i] = max(0,blc[i]);

                  if (a[i] == ')') blc[i] ++;
                  else blc[i] --;
                  if (blc[i] < 0) ans[i] = 'B';
            }
            for (int i = 0; i < n; i ++) {
                  if (ans[i] == 'B') {
                        if (a[i] == ')') {
                              int f = 0;
                              for (int j = 0; j < i; j ++) {
                                    if (ans[j] == '0' && a[j] == '('){ ans[j] = 'G',f = 1;break;}
                              }
                              if (!f) {
                                    puts("impossible");
                                    flag = 1;
                                    break;
                              }
                        }
                        else {
                              int f = 0;
                              for (int j = i + 1; j < n; j ++) {
                                    if (ans[j] == '0' && a[j] == ')') { ans[j] = 'G',f = 1;break;
                                    }
                              }
                              if (!f) {
                                    puts("impossible");
                                    flag = 1;
                                    break;
                              }
                        }
                  }
            }
            if (flag) continue;

            for (int i = 0; i < n; i ++) {
                  if (ans[i] == '0') ans[i] = 'R';
                  cout << ans[i];
            }

            cout << endl;
      }
}

Compilation message

parentrises.cpp:23:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
parentrises.cpp: In function 'int main()':
parentrises.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int i = 0; i < a.size(); i ++) {
                             ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 3 ms 592 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 3 ms 592 KB Output is correct
4 Correct 2 ms 592 KB Output is correct
5 Correct 3 ms 592 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 2 ms 680 KB Output is correct
8 Correct 3 ms 724 KB Output is correct
9 Correct 2 ms 724 KB Output is correct
10 Correct 3 ms 736 KB Output is correct
11 Correct 5 ms 736 KB Output is correct
12 Correct 5 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 12 ms 748 KB Output is correct
15 Correct 4 ms 764 KB Output is correct
16 Correct 21 ms 764 KB Output is correct
17 Correct 15 ms 1948 KB Output is correct
18 Correct 152 ms 1948 KB Output is correct
19 Correct 15 ms 1948 KB Output is correct
20 Correct 18 ms 1948 KB Output is correct
21 Correct 178 ms 1948 KB Output is correct
22 Runtime error 46 ms 6556 KB Execution killed with signal 11 (could be triggered by violating memory limits)
23 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6556 KB Expected integer, but "impossible" found
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6556 KB Expected integer, but "impossible" found
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 6556 KB Expected integer, but "impossible" found