Submission #345383

#TimeUsernameProblemLanguageResultExecution timeMemory
345383casperwangTropical Garden (IOI11_garden)C++14
0 / 100
1 ms492 KiB
#include "garden.h" #include "gardenlib.h" #include <bits/stdc++.h> #define All(x) x.begin(), x.end() #define pb emplace_back #define pii pair<int,int> #define ff first #define ss second using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } const int MAXN = 150000; const int MAXQ = 2000; void count_routes(int N, int M, int P, int R[MAXN][2], int Q, int G[MAXQ]) { vector <vector<int>> tmp(N), path(2*N); for (int i = 0; i < M; i++) { tmp[R[i][0]].pb(R[i][1]); tmp[R[i][1]].pb(R[i][0]); } for (int i = 0; i < N; i++) { int t = tmp[i][0]; t = (tmp[t][0] == i && tmp[t].size() > 1) ? t+N : t; path[t].pb(i); if (tmp[i].size() > 1) { t = tmp[i][1]; t = (tmp[t][0] == i && tmp[t].size() > 1) ? t+N : t; path[t].pb(i+N); } } vector <int> vis1(2*N), vis2(2*N); queue <int> nxt; nxt.push(P); while (nxt.size()) { int now = nxt.front(); nxt.pop(); for (int i : path[now]) if (!vis1[i]) vis1[i] = vis1[now]+1, nxt.push(i); } nxt.push(P+N); while (nxt.size()) { int now = nxt.front(); nxt.pop(); for (int i : path[now]) if (!vis2[i]) vis2[i] = vis2[now]+1, nxt.push(i); } for (int q = 0; q < Q; q++) { int ans = 0; for (int i = 0; i < N; i++) { if (G[q] == vis1[i] || G[q] == vis2[i]) ans++; else if (G[q] == vis1[i] + vis2[P] || G[q] == vis2[i] + vis1[P+N]) ans++; else if (vis1[P] && (G[q] - vis1[i]) % vis1[P] == 0) ans++; else if (vis2[P+N] && (G[q] - vis1[i] - vis2[P]) % vis2[P+N] == 0) ans++; else if (vis2[P+N] && (G[q] - vis2[i]) % vis2[P+N] == 0) ans++; else if (vis1[P] && (G[q] - vis2[i] - vis1[P+N]) % vis1[P] == 0) ans++; } assert(ans); answer(ans); } return; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...