# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
963148 | 2024-04-14T15:13:21 Z | Amr | 열대 식물원 (Tropical Garden) (IOI11_garden) | C++17 | 7 ms | 4700 KB |
#include "garden.h" #include "gardenlib.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define sz size() #define all(x) (x).begin(),(x).end() const int N = 1002; const int Log = 32; vector<pair<ll,ll> > v[N]; ll lst[N]; vector<ll> vec; ll vis[N]; pair<ll,ll> sp[N][Log][2]; void dfs1(ll x) { if(vis[x]) return; vis[x] = 1; vec.push_back(x); for(int i = 0; i < v[x].sz; i++) { dfs1(v[x][i].S); } } void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) { for(int i = 0; i < M; i++) { ll x = R[i][0] , y = R[i][1]; v[x].push_back({i,y}); v[y].push_back({i,x}); } for(int i = 0; i < N; i++) sort(all(v[i])); dfs1(P); if(vec.sz==2) { answer(1); return; } for(int i = 0; i < vec.sz; i++) { ll x = vec[i]; ll y = v[x][0].S; ll m = -1; if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1; sp[x][0][0] = {y,m}; if(v[x].sz==1) {sp[x][0][1] = {-1,-1}; continue;} m = -1; y = v[x][1].S; if(v[y][0].S==x) m = 0; else if(v[y][1].S==x) m = 1; sp[x][0][1] = {y,m}; } for(int j = 1; j < Log; j++) { for(int i = 0; i < vec.sz; i++) { ll x = vec[i]; ll y = sp[x][j-1][0].F,m=0; if(v[y].sz>1&&sp[x][j-1][0].S==0) m = 1; sp[x][j][0] = sp[y][j-1][m]; if(v[x].sz==1) continue; y = sp[x][j-1][1].F,m=0; if(v[y].sz>1&&sp[x][j-1][1].S==0) m = 1; sp[x][j][1] = sp[y][j-1][m]; } } /*for(int i = 0; i < N; i++){ for(int j = 0; j < 3; j++) { cout << sp[i][j][0].F << " " << sp[i][j][1].F << endl; } cout << endl; }*/ ll ans = 0; for(int i = 0; i < vec.sz; i++) { ll x = vec[i], y = 0; ll k = G[0]; for(int j = Log-1; j >= 0; j--) { if(k<(1LL<<j)) continue; k-=(1LL<<j); ll x2 = sp[x][j][y].F,m = sp[x][j][y].S; if(m==0&&v[x2].sz>1) m = 1; else m = 0; x = x2, y = m; } //cout << x << " "; if(x==P) ans++; } answer(ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2652 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2392 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 2 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2652 KB | Output is correct |
9 | Correct | 4 ms | 3000 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2652 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2392 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 2 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2652 KB | Output is correct |
9 | Correct | 4 ms | 3000 KB | Output is correct |
10 | Correct | 1 ms | 2392 KB | Output is correct |
11 | Runtime error | 7 ms | 4700 KB | Execution killed with signal 11 |
12 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2652 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
3 | Correct | 1 ms | 2652 KB | Output is correct |
4 | Correct | 1 ms | 2392 KB | Output is correct |
5 | Correct | 1 ms | 2396 KB | Output is correct |
6 | Correct | 2 ms | 2648 KB | Output is correct |
7 | Correct | 1 ms | 2396 KB | Output is correct |
8 | Correct | 1 ms | 2652 KB | Output is correct |
9 | Correct | 4 ms | 3000 KB | Output is correct |
10 | Correct | 1 ms | 2392 KB | Output is correct |
11 | Runtime error | 7 ms | 4700 KB | Execution killed with signal 11 |
12 | Halted | 0 ms | 0 KB | - |