# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
474682 | hidden1 | 열대 식물원 (Tropical Garden) (IOI11_garden) | C++14 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "gardenlib.h"
#include "garden.h"
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
n = N;
fill_n(mn, n, 1e8);
for(int i = 0; i < M; i ++) {
int a = R[i][0], b = R[i][1];
help[a].push_back(i);
help[b].push_back(i);
chkmin(mn[a], i);
chkmin(mn[b], i);
}
for(int i = 0; i < n; i ++) {
sort(help[i].begin(), help[i].end());
if(help[i].size() == 0) {
continue;
} else {
// ???
int best = help[i][0];
par[i] = R[best][0] + R[best][1] - i;
if(mn[par[i]] == best) {
par[i] += n;
}
best = help[i][1 % help[i].size()];
par[i + n] = R[best][0] + R[best][1] - i;
if(mn[par[i + n]] == best) {
par[i + n] += n;
}
}
}
for(int i = 0; i < 2 * n; i ++) {
g[par[i]].push_back(i);
}
cnt[0] = cnt[1] = -1;
fill_n(used, n, 0);
dfs(P, 0);
cout << endl;
fill_n(used, n, 0);
dfs(P + n, 1);
for(int i = 0; i < 2; i ++) {
if(cnt[i] == -1) {continue;}
for(int j = cnt[i]; j < MAX_N; j ++) {
for(auto it : ans[i][j]) {
ans[i][it % cnt[i]].push_back(it);
}
}
}
for(int i = 0; i < Q; i ++) {
int ret = 0;
if(cnt[0] != -1) {
ret += upper_bound(ans[0][G[i] % cnt[0]].begin(), ans[0][G[i] % cnt[0]].end(), G[i]) - ans[0][G[i] % cnt[0]].begin();
} else {
ret += ans[0][G[i]].size();
}
if(cnt[1] != -1) {
ret += upper_bound(ans[1][G[i] % cnt[1]].begin(), ans[1][G[i] % cnt[1]].end(), G[i]) - ans[1][G[i] % cnt[1]].begin();
} else {
ret += ans[1][G[i]].size();
}
answer(ret);
}
}