Submission #1080627

#TimeUsernameProblemLanguageResultExecution timeMemory
1080627thelegendary08City (JOI17_city)C++14
8 / 100
150 ms32912 KiB
#include "Encoder.h"
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define vi vector<ll>
#define vvi vector<vector<int>>
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define mii map<int,int>
#define mll map<long long int, long long int>
#define mivi map<int,vector<int>>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int mxn = 250005;

vi order;
vi adj[mxn];
vb vis(mxn, 0);
vi sz(mxn, 0);
vi code(mxn, 0);
void dfs(int x){
	if(vis[x])return;
	int cur = 1;
	vis[x] = 1;
	order.pb(x);
	vpii please;
	
	for(auto u : adj[x]){
		please.pb({sz[u], u});
	}
	sort(please.rbegin(), please.rend());
	for(auto u : please){
		dfs(u.second);
	}
}
int getsz(int x, int from){
	int cur = 1;
	for(auto u : adj[x]){
		if(u != from){
			cur += getsz(u, x);
		}
	}
	sz[x] = cur;
	return cur;
}
void Encode(int n, int a[], int b[])
{
	f0r(i, n-1){
		adj[a[i]].pb(b[i]);
		adj[b[i]].pb(a[i]);
	}
	getsz(0, -1);
	dfs(0);
	f0r(i, n){
		code[order[i]] = i;
	}
	
	
	for (int i = 0; i < n; ++i) {
		ll c;
		if(sz[i] < 125000) c = 125000 * code[i] + sz[i];
		else c = 125000* 125000 + 250000 * code[i] + sz[i];
		Code(i, c);
		//cout<<i<<' '<<sz[i]<<' '<<code[i]<<'\n';
	}
}
#include "Device.h"
#define ll long long
void InitDevice()
{
}

int Answer(long long S, long long T)
{
	ll szs, cs, szt, ct;
	//cout<<S<<' '<<T<<'\n';
	if(S >= 250000 * 125000){
		S -= 250000ll * 125000ll;
		szs = S % 250000ll;
		cs = S / 250000ll;
	}
	else{
		szs = S % 125000ll;
		cs = S / 125000ll;
	}
	if(T >= 250000ll * 125000ll){
		T -= 250000ll * 125000ll;
		szt = T % 250000ll;
		ct = T / 250000ll;
	}
	else{
		szt = T % 125000ll;
		ct = T/ 125000ll;
	}
	
	//cout<<cs<<' '<<ct<<' '<<szs<<' '<<szt<<'\n';
	if(cs + szs > ct && ct > cs)return 1;
	if(ct + szt > cs && cs > ct)return 0;
	return 2;
}

Compilation message (stderr)

Encoder.cpp: In function 'void dfs(int)':
Encoder.cpp:29:6: warning: unused variable 'cur' [-Wunused-variable]
   29 |  int cur = 1;
      |      ^~~
Encoder.cpp: In function 'void Encode(int, int*, int*)':
Encoder.cpp:68:18: warning: integer overflow in expression of type 'int' results in '-1554869184' [-Woverflow]
   68 |   else c = 125000* 125000 + 250000 * code[i] + sz[i];
      |            ~~~~~~^~~~~~~~

Device.cpp: In function 'int Answer(long long int, long long int)':
Device.cpp:11:17: warning: integer overflow in expression of type 'int' results in '1185228928' [-Woverflow]
   11 |  if(S >= 250000 * 125000){
      |          ~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...