Submission #996902

#TimeUsernameProblemLanguageResultExecution timeMemory
996902AdamGSCity (JOI17_city)C++17
100 / 100
257 ms39936 KiB
#include "Encoder.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const ll K=396736; const int LIM=25e4+7; vector<int>V[LIM]; ll pre[LIM], lpre; ll rnd(ll x) { if(x<=50) return x; x-=50; ll po=0, ko=1000000000; while(po<ko) { ll sr=(po+ko)/2; if(sr*sr<x) po=sr+1; else ko=sr; } return po*po+50; } ll cod(ll x) { if(x<=50) return x; x-=50; ll po=0, ko=1000000000; while(po<ko) { ll sr=(po+ko)/2; if(sr*sr<x) po=sr+1; else ko=sr; } return po+50; } void DFS(int x, int o) { pre[x]=lpre; ++lpre; for(auto i : V[x]) if(i!=o) DFS(i, x); ll z=lpre-pre[x]; lpre=pre[x]+rnd(z); Code(x, pre[x]+K*cod(z)); } void Encode(int n, int A[], int B[]) { rep(i, n-1) { V[A[i]].pb(B[i]); V[B[i]].pb(A[i]); } DFS(0, 0); }
#include "Device.h" #include<bits/stdc++.h> typedef long long ll; #define rep(a, b) for(int a = 0; a < (b); ++a) #define st first #define nd second #define pb push_back #define all(a) a.begin(), a.end() const ll K=396736; void InitDevice() {} ll dec(ll x) { if(x<=50) return x; x-=50; return x*x+50; } bool oc(ll x, ll y) { ll a=x%K, b=y%K, c=x/K; return a<=b && b<a+dec(c); } int Answer(ll S, ll T) { if(oc(S, T)) return 1; if(oc(T, S)) return 0; return 2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...