Submission #1077199

#TimeUsernameProblemLanguageResultExecution timeMemory
1077199mindiyakStations (IOI20_stations)C++14
10 / 100
654 ms1840 KiB
#include "stations.h" #include <vector> #include <queue> #include <iostream> #include <cmath> #include <algorithm> using namespace std; vector<vector<int>> paths(1001); vector<int> dist(1001,-1); void dfs(int pos,int len,int level){ if(dist[pos] != -1)return; dist[pos] = len; int cnt = 1; for(int i:paths[pos]){ if(dist[i] != -1)continue; dfs(i,len+(cnt*int(pow(10,level))),level+1); cnt ++; } } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { std::vector<int> labels(n); paths = vector<vector<int>>(1001); dist = vector<int>(1001,-1); for(int i = 0;i<n-1;i++){ paths[u[i]].push_back(v[i]); paths[v[i]].push_back(u[i]); } int head = 1; // for (int i = 0; i < n; i++) { // if(paths[i].size() > 2){ // head = i; // } // } dist[head] = 0; int cnt = 1; for(int i:paths[head]){ dfs(i,cnt,1); cnt ++; } cerr << head << endl; for (int i = 0; i < n; i++) { labels[i] = dist[i]; cerr << labels[i] << " "; } cerr << endl; return labels; } int find_next_station(int s, int t, std::vector<int> c) { sort(c.begin(),c.end()); if (c.size() == 1) return c[0]; if(s == 0){ for (int v : c){ if (v%10 == t%10) return v; } } for (int v : c) if (v == t) return t; if(s<t){ int level = 0; for (int v : c){ if(v==0)continue; int cur = 0; while(v>0){ cur ++; v/=10; } level = max(level,cur); } cerr << "DEBUG " << s << " " << t << " " << level << " " << t%int(pow(10,level)) << " | "; for (int v : c){ if(v==0)continue; cerr << v << " "; if(t%int(pow(10,level)) == v){ cerr << endl; return v; } } } return c[0]; }
#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...