Submission #231830

#TimeUsernameProblemLanguageResultExecution timeMemory
231830IOrtroiiiTropical Garden (IOI11_garden)C++14
Compilation error
0 ms0 KiB
#include "garden.h" #include "gardenlib.h" using namespace std; void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { vector<int> deg(N); vector<int> best(N, -1); for (int i = 0; i < M; ++i) { for (int z = 0; z < 2; ++z) { ++deg[R[i][z]]; if (best[R[i][z]] == -1) best[R[i][z]] = i; } } vector<int> nxt(N * 2, -1); for (int i = 0; i < M; ++i) { for (int z = 0; z < 2; ++z) { int to = R[i][!z]; if (best[R[i][!z]] == i && deg[R[i][!z]] > 1) to += N; if (nxt[R[i][z]] == -1) nxt[R[i][z]] = to; else if (nxt[R[i][z] + N] == -1) nxt[R[i][z] + N] = to; } } vector<vector<int>> adj(2 * N); for (int i = 0; i < N; ++i) { adj[nxt[i]].emplace_back(i); if (deg[i] > 1) adj[nxt[i + N]].emplace_back(i + N); } vector<pair<int, int>> qs; for (int i = 0; i < Q; ++i) qs.emplace_back(G[i], i); sort(qs.begin(), qs.end()); vector<int> ans(Q); auto go = [&](int start) { vector<int> dist(2 * N, -1); vector<int> q; dist[start] = 0; q.emplace_back(start); for (int i = 0; i < int(q.size()); ++i) { int v = q[i]; for (int u : adj[v]) if (dist[u] == -1) { dist[u] = dist[v] + 1; q.emplace_back(u); } } vector<int> dists; for (int v : q) if (v < N) dists.emplace_back(dist[v]); int len = 0; vector<bool> visited(2 * N); int v = start; while (!visited[v]) { visited[v] = true; v = nxt[v]; ++len; } if (v != start) len = -1; vector<int> cnts(2 * N); int ptr = 0; for (int i = 0; i < Q; ++i) { while (ptr < int(dists.size()) && dists[ptr] <= qs[i].first) { int cur = dists[ptr++]; if (len != -1) cur %= len; ++cnts[cur]; } int cur = qs[i].first; if (len != -1) cur %= len; if (cur < 2 * N) ans[qs[i].second] += cnts[cur]; } }; go(P); if (deg[P] > 1) go(P + N); for (int i = 0; i < Q; ++i) answer(ans[i]); }

Compilation message (stderr)

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:6:4: error: 'vector' was not declared in this scope
    vector<int> deg(N);
    ^~~~~~
garden.cpp:6:11: error: expected primary-expression before 'int'
    vector<int> deg(N);
           ^~~
garden.cpp:7:11: error: expected primary-expression before 'int'
    vector<int> best(N, -1);
           ^~~
garden.cpp:10:12: error: 'deg' was not declared in this scope
          ++deg[R[i][z]];
            ^~~
garden.cpp:11:14: error: 'best' was not declared in this scope
          if (best[R[i][z]] == -1) best[R[i][z]] = i;
              ^~~~
garden.cpp:14:11: error: expected primary-expression before 'int'
    vector<int> nxt(N * 2, -1);
           ^~~
garden.cpp:18:14: error: 'best' was not declared in this scope
          if (best[R[i][!z]] == i && deg[R[i][!z]] > 1) to += N;
              ^~~~
garden.cpp:18:37: error: 'deg' was not declared in this scope
          if (best[R[i][!z]] == i && deg[R[i][!z]] > 1) to += N;
                                     ^~~
garden.cpp:19:14: error: 'nxt' was not declared in this scope
          if (nxt[R[i][z]] == -1) nxt[R[i][z]] = to;
              ^~~
garden.cpp:23:18: error: expected primary-expression before 'int'
    vector<vector<int>> adj(2 * N);
                  ^~~
garden.cpp:25:7: error: 'adj' was not declared in this scope
       adj[nxt[i]].emplace_back(i);
       ^~~
garden.cpp:25:11: error: 'nxt' was not declared in this scope
       adj[nxt[i]].emplace_back(i);
           ^~~
garden.cpp:26:11: error: 'deg' was not declared in this scope
       if (deg[i] > 1) adj[nxt[i + N]].emplace_back(i + N);
           ^~~
garden.cpp:28:11: error: 'pair' was not declared in this scope
    vector<pair<int, int>> qs;
           ^~~~
garden.cpp:28:16: error: expected primary-expression before 'int'
    vector<pair<int, int>> qs;
                ^~~
garden.cpp:29:32: error: 'qs' was not declared in this scope
    for (int i = 0; i < Q; ++i) qs.emplace_back(G[i], i);
                                ^~
garden.cpp:30:9: error: 'qs' was not declared in this scope
    sort(qs.begin(), qs.end());
         ^~
garden.cpp:30:4: error: 'sort' was not declared in this scope
    sort(qs.begin(), qs.end());
    ^~~~
garden.cpp:30:4: note: suggested alternative: 'short'
    sort(qs.begin(), qs.end());
    ^~~~
    short
garden.cpp:31:11: error: expected primary-expression before 'int'
    vector<int> ans(Q);
           ^~~
garden.cpp: In lambda function:
garden.cpp:33:14: error: expected primary-expression before 'int'
       vector<int> dist(2 * N, -1);
              ^~~
garden.cpp:34:14: error: expected primary-expression before 'int'
       vector<int> q;
              ^~~
garden.cpp:35:7: error: 'dist' was not declared in this scope
       dist[start] = 0;
       ^~~~
garden.cpp:35:7: note: suggested alternative: 'int'
       dist[start] = 0;
       ^~~~
       int
garden.cpp:36:7: error: 'q' was not declared in this scope
       q.emplace_back(start);
       ^
garden.cpp:39:23: error: 'adj' was not declared in this scope
          for (int u : adj[v]) if (dist[u] == -1) {
                       ^~~
garden.cpp:44:14: error: expected primary-expression before 'int'
       vector<int> dists;
              ^~~
garden.cpp:45:20: error: unable to deduce 'auto&&' from 'q'
       for (int v : q) if (v < N) dists.emplace_back(dist[v]);
                    ^
garden.cpp:45:34: error: 'dists' was not declared in this scope
       for (int v : q) if (v < N) dists.emplace_back(dist[v]);
                                  ^~~~~
garden.cpp:47:14: error: expected primary-expression before 'bool'
       vector<bool> visited(2 * N);
              ^~~~
garden.cpp:49:15: error: 'visited' was not declared in this scope
       while (!visited[v]) {
               ^~~~~~~
garden.cpp:51:14: error: 'nxt' was not declared in this scope
          v = nxt[v];
              ^~~
garden.cpp:55:14: error: expected primary-expression before 'int'
       vector<int> cnts(2 * N);
              ^~~
garden.cpp:58:27: error: 'dists' was not declared in this scope
          while (ptr < int(dists.size()) && dists[ptr] <= qs[i].first) {
                           ^~~~~
garden.cpp:61:15: error: 'cnts' was not declared in this scope
             ++cnts[cur];
               ^~~~
garden.cpp:61:15: note: suggested alternative: 'int'
             ++cnts[cur];
               ^~~~
               int
garden.cpp:65:27: error: 'ans' was not declared in this scope
          if (cur < 2 * N) ans[qs[i].second] += cnts[cur];
                           ^~~
garden.cpp:65:48: error: 'cnts' was not declared in this scope
          if (cur < 2 * N) ans[qs[i].second] += cnts[cur];
                                                ^~~~
garden.cpp:65:48: note: suggested alternative: 'int'
          if (cur < 2 * N) ans[qs[i].second] += cnts[cur];
                                                ^~~~
                                                int
garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:69:8: error: 'deg' was not declared in this scope
    if (deg[P] > 1) go(P + N);
        ^~~
garden.cpp:70:39: error: 'ans' was not declared in this scope
    for (int i = 0; i < Q; ++i) answer(ans[i]);
                                       ^~~