Submission #996894

# Submission time Handle Problem Language Result Execution time Memory
996894 2024-06-11T11:53:49 Z AdamGS City (JOI17_city) C++17
8 / 100
3000 ms 13108 KB
#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=4596736;
const int LIM=25e4+7;
vector<int>V[LIM];
ll pre[LIM], lpre;
ll rnd(ll x) {
  if(x<=100) return x;
  x-=100;
  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+100;
}
ll cod(ll x) {
  if(x<=100) return x;
  x-=100;
  ll po=0, ko=1000000000;
  while(po<ko) {
    ll sr=(po+ko)/2;
    if(sr*sr<x) po=sr+1;
  }
  return po+100;
}
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=4596736;
void InitDevice() {}
ll dec(ll x) {
  if(x<=100) return x;
  x-=100;
  return x*x+100;
}
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 time Memory Grader output
1 Correct 1 ms 13072 KB Output is correct
2 Correct 2 ms 13068 KB Output is correct
3 Correct 1 ms 13084 KB Output is correct
4 Correct 3 ms 13072 KB Output is correct
5 Correct 2 ms 13072 KB Output is correct
6 Correct 2 ms 13072 KB Output is correct
7 Correct 1 ms 13108 KB Output is correct
8 Correct 1 ms 13072 KB Output is correct
9 Correct 1 ms 13084 KB Output is correct
10 Correct 2 ms 13084 KB Output is correct
11 Correct 1 ms 13072 KB Output is correct
12 Correct 1 ms 13084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3016 ms 10584 KB Time limit exceeded
2 Halted 0 ms 0 KB -