답안 #956794

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
956794 2024-04-02T13:17:20 Z Lukap Homework (CEOI22_homework) C++14
0 / 100
163 ms 158228 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e6;

string s;
int n, uk;
int l[MAXN], r[MAXN], tip[MAXN], lo[MAXN], hi[MAXN], vel[MAXN];
vector<int> v;
vector<int> zarez[30];
int koji[30];

void unos (int l_g, int r_g, int xi) {
    int x = uk;
    uk++;
    if (r_g == l_g) {
        n++;
        return;
    }

    char a = s[l_g + 1];

    int zag = zarez[xi][koji[xi]];
    koji[xi]++;

    if (a == 'i') tip[x] = 0;
    else tip[x] = 1;

    l[x] = uk;
    unos (l_g + 4, zag - 1, xi + 1);

    r[x] = uk;
    unos (zag + 1, r_g - 1, xi + 1);

}

void dfs (int x, int glavn) {
    if (l[x] == -1) {
        vel[glavn]++;
        lo[glavn] = 1;
        hi[glavn] = n;
        return;
    }

    if (tip[x] != tip[0]) {
        vel[glavn]++;
        dfs (l[x], x);
        dfs (r[x], x);
        if (!tip[x]) hi[x] -= vel[x] - 1;
        else lo[x] += vel[x] - 1;

        lo[glavn] = min (lo[glavn], lo[x]);
        hi[glavn] = max (hi[glavn], hi[x]);
    }

    else {
        dfs (l[x], glavn);
        dfs (r[x], glavn);
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie (0);
    cout.tie (0);
    memset (l , -1, sizeof (l));
    memset (r, -1, sizeof (r));

    cin >> s;
    int brojem = 0;
    for (int i = 0; i < (int) s.size (); i++) {
        if (s[i] == '(') brojem++;
        if (s[i] == ')') brojem--;
        if (s[i] == ',') zarez[brojem - 1].push_back (i);
    }
    unos (0, s.size () - 1, 0);

    for (int i = 0; i < uk; i++) {
        lo[i] = n;
        hi[i] = 0;
    }

    dfs (0, 0);
    if (!tip[0]) hi[0] -= vel[0] - 1;
    else lo[0] += vel[0] - 1;

    cout << hi[0] - lo[0] + 1;

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 22772 KB Output is correct
2 Correct 9 ms 22620 KB Output is correct
3 Correct 4 ms 22620 KB Output is correct
4 Incorrect 4 ms 22620 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 22772 KB Output is correct
2 Correct 9 ms 22620 KB Output is correct
3 Correct 4 ms 22620 KB Output is correct
4 Incorrect 4 ms 22620 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 163 ms 158228 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 22772 KB Output is correct
2 Correct 9 ms 22620 KB Output is correct
3 Correct 4 ms 22620 KB Output is correct
4 Incorrect 4 ms 22620 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 22772 KB Output is correct
2 Correct 9 ms 22620 KB Output is correct
3 Correct 4 ms 22620 KB Output is correct
4 Incorrect 4 ms 22620 KB Output isn't correct
5 Halted 0 ms 0 KB -