제출 #427389

#제출 시각아이디문제언어결과실행 시간메모리
427389kai824City (JOI17_city)C++17
30 / 100
655 ms51720 KiB
#include "Encoder.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; vector<int> adjl[250005]; ll pre[250005],sub[250005],nex; ll cnts[250005]; void init(){ for(int i=1;i<250001;i++){ cnts[i]=cnts[i-1]+(250001-i); } } ll convert(int x,int y){//returns no. of smaller pairs... y-=x; assert(cnts[x]+y<cnts[x+1]); return cnts[x]+y; } void dfs(int node,int p=-1){ pre[node]=nex++; for(int x:adjl[node]){ if(x==p)continue; dfs(x,node); } sub[node]=nex-1; // cout<<node<<' '<<pre[node]<<' '<<sub[node]<<'\n'; Code(node,convert(pre[node],sub[node])); } void Encode(int n, int a[], int b[]){ init(); for(int i=0;i+1<n;i++){ adjl[a[i]].push_back(b[i]); adjl[b[i]].push_back(a[i]); } dfs(0); //Code(i, 0LL): node, label... }
#include "Device.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; ll cnt[250005]; void InitDevice(){ cnt[0]=0; for(int i=1;i<250001;i++){ cnt[i]=cnt[i-1]+(250001-i); } } void unpack(ll x,int&a, int&b){ for(int i=0;i<10;i++){//check smol numbers manually... if(x>=cnt[i]){ a=i; b=x-cnt[i]; }else break; } a=upper_bound(cnt,cnt+250001,x)-cnt-1; b=x-cnt[a]+a; //cout<<x<<' '<<a<<' '<<b<<'\n'; } int Answer(long long s, long long t){ int p1,p2,s1,s2; unpack(s,p1,s1); unpack(t,p2,s2); if(p1<p2 && p2<=s1)return 1; if(p2<p1 && p1<=s2)return 0; return 2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...