# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031101 | s_tree | City (JOI17_city) | C++17 | 104 ms | 20636 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Encoder.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 300'010;
vector<long long> nums;
vector<int> g[N];
int tim=0;
long long f[N], s[N];
void dfs(int at, int p) {
f[at] = tim;
for(int to:g[at]) {
if(to==p)continue;
dfs(to, at);
}
// s[at]=tim++;
auto it = lower_bound(nums.begin(), nums.end(), tim-f[at]+1);
// cout << (*it) << ", " << tim-f[at]+1 << endl;
s[at] = (it-nums.begin());
tim = f[at]+nums[s[at]];
}
void Encode(int n, int A[], int B[])
{
long double d = 1.05;
long double val = d;
while(val <= N) {
if(!nums.size() or nums.back()!=(int)val)
nums.push_back(val);
val*=d;
}
for(int i=0;i+1<n;i++) {
g[A[i]].push_back(B[i]);
g[B[i]].push_back(A[i]);
}
dfs(0, -1);
for(int i = 0;i<n;i++) {
// cout << f[i] << " " << f[i]+nums[s[i]]-1 << "\n";
// cout << ((long long)s[i]*N*3 +f[i])/3*N << endl;
Code(i, (long long)(f[i])*nums.size() + s[i]);
}
// cout << "A" << endl;
}
#include "Device.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 300'010;
vector<long long> nms;
void InitDevice()
{
long double d = 1.05;
long double val = d;
while(val <= N) {
if(!nms.size() or nms.back()!=(int)val)
nms.push_back(val);
val*=d;
}
}
int Answer(long long S, long long T)
{
long long fs = S/(N);
long long ss = fs-1+nms[S%(nms.size())];
long long ft = T/(N);
long long st = ft-1+nms[T%(nms.size())];
if(fs <= ft and st <= ss)return 1;
if(ft <= fs and ss <= st)return 0;
return 2;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |