제출 #1320802

#제출 시각아이디문제언어결과실행 시간메모리
1320802yeyso2이주 (IOI25_migrations)C++20
0 / 100
28 ms872 KiB
#include "migrations.h" using namespace std; #include <bits/stdc++.h> vector<vector<int>> adj; vector<int> dist_from_0; int farthest_from(int src) { int n = (int)adj.size(); vector<int> dist(n, -1); queue<int> q; dist[src] = 0; q.push(src); int best = src; while(!q.empty()) { int u = q.front(); q.pop(); if(dist[u] > dist[best]) best = u; for(int v : adj[u]) if(dist[v] == -1) { dist[v] = dist[u] + 1; q.push(v); } } return best; } int furtherest = 0; int end_1; int end_2; set<int> seen; int send_message(int N, int i, int Pi) { if(i == 1){ adj.resize(N); dist_from_0.resize(N, 0); adj[Pi].push_back(1); return 0; } adj[Pi].push_back(i); if(i < 9997) return 0; if(i == 9997){ end_1 = farthest_from(0); end_2 = farthest_from(end_1); if(end_1 > end_2){ int temp = end_1; end_1 = end_2; end_2 = temp; } seen.insert(end_1); seen.insert(end_2); return end_1; } if(i == 9998){ return end_2; } if(i == 9999){ int new_end1 = farthest_from(0); int new_end2 = farthest_from(new_end1); vector<int> new_ends; new_ends = {new_end1, new_end2}; sort(new_ends.begin(), new_ends.end()); int res = 0; if(seen.count(new_ends[0]) && seen.count(new_ends[1])){ return 0; // none replaced } if(new_ends[0] == 9998 && new_ends[1] == 9999){ return 20000; } // both replaced // one replaced if(new_ends[0] <= 9997 && new_ends[1] >= 9998){ res = new_ends[0]; // just need to communicate the node that was replaced if(res == end_1){ return new_ends[1]; } else { return new_ends[1] + 10000; } } } return 0; } std::pair<int, int> longest_path(std::vector<int> S) { if(S.back() == 0){ return {S[9997], S[9998]}; } if(S.back() == 20000){ return {9998, 9999}; } if(S.back() < 10000){ return {S[9997], S.back()}; } else { return {S[9998], S.back() - 10000}; } return {0, 0}; } /* g++ -std=gnu++20 -Wall -O2 -pipe -static -g -o migrations grader.cpp migrations.cpp 6 0 0 2 2 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...