Submission #956788

# Submission time Handle Problem Language Result Execution time Memory
956788 2024-04-02T13:07:01 Z Lukap Homework (CEOI22_homework) C++14
0 / 100
1000 ms 31996 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;

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

    char a = s[l_g + 1];
    int zag, br = 0;
    for (int i = l_g; i <= r_g; i++) {
        if (s[i] == '(') br++;
        if (s[i] == ')') br--;

        if (s[i] == ',' && br == 1) zag = i;
     }

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

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

    r[x] = uk;
    unos (zag + 1, r_g - 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;
    unos (0, s.size () - 1);

    cout << 2;
    return 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;
}

Compilation message

Main.cpp: In function 'void unos(int, int)':
Main.cpp:36:10: warning: 'zag' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |     unos (zag + 1, r_g - 1);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 18268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 18268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1057 ms 31996 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 18268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 18268 KB Output isn't correct
2 Halted 0 ms 0 KB -