제출 #927011

#제출 시각아이디문제언어결과실행 시간메모리
927011ByeWorld기지국 (IOI20_stations)C++14
0 / 100
534 ms984 KiB
#include "stations.h" #include <vector> #include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef pair<int,int> pii; typedef pair<pii,int> ipii; const int MAXN = 1e3+10; const int MAX = 1e3+1; int n, k; vector <int> adj[MAXN], dw[MAXN]; vector <int> lab; int chi[MAXN], val[MAXN], cnt; void dfs(int nw, int par){ // build val, tergantung dfs val[nw] = cnt++; for(auto nx : adj[nw]){ if(nx == par) continue; dw[nw].pb(nx); dfs(nx, nw); } } void bd(int nw){ chi[nw] = val[nw]; for(auto nx : dw[nw]){ bd(nx); chi[nw] = max(chi[nw], chi[nx]); } } vector<int> label(int N, int K, vector<int> u, vector<int> v) { n = N; k = K; lab.clear(); lab.resize(n); cnt = 0; for(int i=0; i<=n; i++){ adj[i].clear(); dw[i].clear(); chi[i] = 0; val[i] = 0; } for(int i=0; i<n-1; i++){ adj[u[i]].pb(v[i]); adj[v[i]].pb(u[i]); } dfs(0, -1); bd(0); for(int i=0; i<n; i++){ lab[i] = val[i] + chi[i]*MAX; } //for(int i=0; i<n; i++) cout << i << ' ' << val[i] << ' ' << chi[i] << ' '<< lab[i] << " p\n"; return lab; } int find_next_station(int s, int t, vector<int> c) { // c sorted int num = c.size(); vector <pii> val(num); for(int i=0; i<c.size(); i++){ val[i].fi = c[i]%MAX; val[i].se = c[i] / MAX; // idx, max idx di subtree } sort(val.begin(), val.end()); // based on idx //for(auto in : val) cout << in.fi << ' '<< in.se << " xx\n"; int valt = t%MAX, idx = -1; if(s%MAX==0){ // s itu root for(int i=0; i<val.size(); i++){ if(val[i].fi <= valt){ idx = i; } } return (val[idx].fi + val[idx].se*MAX); } int mx = s/MAX; // kalo nx==0, brati gk ada nx for(int i=1; i<val.size(); i++){ if(val[i].fi <= valt){ idx = i; } } if(valt < val[1].fi || valt > mx) idx = 0; // parent return (val[idx].fi + val[idx].se*MAX); }

컴파일 시 표준 에러 (stderr) 메시지

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:58:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |  for(int i=0; i<c.size(); i++){
      |               ~^~~~~~~~~
stations.cpp:67:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |   for(int i=0; i<val.size(); i++){
      |                ~^~~~~~~~~~~
stations.cpp:76:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  for(int i=1; i<val.size(); i++){
      |               ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...