Submission #511068

#TimeUsernameProblemLanguageResultExecution timeMemory
511068tabrTropical Garden (IOI11_garden)C++17
0 / 100
1 ms460 KiB
#include <bits/stdc++.h> using namespace std; #ifdef tabr #include "library/debug.cpp" #else #define debug(...) #endif #include "garden.h" #include "gardenlib.h" void count_routes(int n, int m, int p, int r[][2], int q, int k[]) { vector<vector<int>> g(n); for (int i = 0; i < m; i++) { g[r[i][0]].emplace_back(r[i][1]); g[r[i][1]].emplace_back(r[i][0]); } vector<vector<int>> nxt(30, vector<int>(2 * n)); for (int i = 0; i < n; i++) { nxt[0][i] = g[i][0] + n; nxt[0][i + n] = (g[i].empty() ? g[i][0] + n : g[i][1]); } for (int i = 1; i < 30; i++) { for (int j = 0; j < 2 * n; j++) { nxt[i][j] = nxt[i - 1][nxt[i - 1][j]]; } } for (int i = 0; i < q; i++) { int ans = 0; for (int j = 0; j < n; j++) { int v = j; for (int l = 29; l >= 0; l--) { if (k[i] & (1 << l)) { v = nxt[l][v]; } } if (v % n == p) { ans++; } } answer(ans); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...