# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
331031 |
2020-11-27T04:58:09 Z |
IloveN |
Towns (IOI15_towns) |
C++14 |
|
26 ms |
896 KB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(vr) vr.begin(),vr.end()
#define vi vector<int>
#define vll vector<ll>
#include "towns.h"
const int N=1e3+10;
namespace myrand
{
mt19937 mt(chrono::system_clock::now().time_since_epoch() / chrono::microseconds(1));
ll Int(ll l,ll r) { return uniform_int_distribution<ll> (l,r)(mt);}
}
using namespace myrand;
/*int getDistance(int x,int y)
{
return 0;
}*/
int dis[N][N];
int lim;
int get(int x,int y)
{
if (x==y) return 0;
if (dis[x][y]) return dis[x][y];
lim--;
return (dis[x][y]=dis[y][x]=getDistance(x-1,y-1));
}
bool check_balance(vi &lc,int x,int n,int sub,int s,int t)
{
vi vt;
int siz1=0,siz2=0,siz3=0;
for (int i=1;i<=n;i++)
if (lc[i]<x) siz1++;
else if (lc[i]==x) siz2++,vt.eb(i);
else siz3++;
if (max({siz1,siz2,siz3})>n/2) return false;
if (sub==4) return true;
if (max(siz1,siz3)>n/2) return false;
for (int i : vt)
{
int cnt=0;
for (int j : vt)
if (get(i,j)<dis[s][i]+dis[s][j]-2*x) cnt++;
if (cnt>n/2) return false;
}
return true;
}
int hubDistance(int n, int sub)
{
if (sub==1 || sub==3) lim=n*(n-1)/2;
else if (sub==5) lim=5*n;
else lim=(7*n+1)/2;
int s=Int(1,n),t=0,mx=0;
for (int i=1;i<=n;i++)
for (int j=1;j<=n;j++) dis[i][j]=0;
for (int i=1;i<=n;i++)
if (s!=i)
{
int d=get(s,i);
if (d>mx) mx=d,t=i;
}
for (int i=1;i<=n;i++)
if (i!=t)
{
int d=get(t,i);
dis[t][i]=d;
if (d>mx) mx=d,s=i;
}
int res=mx,flag=0;
vi lc(n+1);
for (int i=1;i<=n;i++)
if (i!=s && i!=t)
{
int d=get(s,i);
int tmp=(d+dis[t][i]-dis[t][s])/2;
res=min(res,max(d-tmp,dis[t][i]-tmp));
}
for (int i=1;i<=n;i++)
{
int d=(dis[s][i]+dis[t][i]-dis[s][t])/2;
if (dis[t][i]-d==res) flag |= 1;
if (dis[s][i]-d==res) flag |= 2;
lc[i]=dis[s][i]-d;
}
if (sub<3) return res;
if (flag&1 && check_balance(lc,mx-res,n,sub,s,t)) return res;
if ((flag>>1)&1 && check_balance(lc,res,n,sub,s,t)) return res;
return -res;
}
/*int main()
{
//freopen("ss.inp","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0);
return 0;
}
*/
Compilation message
towns.cpp: In function 'bool check_balance(std::vector<int>&, int, int, int, int, int)':
towns.cpp:42:57: warning: unused parameter 't' [-Wunused-parameter]
42 | bool check_balance(vi &lc,int x,int n,int sub,int s,int t)
| ~~~~^
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:68:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
68 | int s=Int(1,n),t=0,mx=0;
| ~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
756 KB |
Output is correct |
2 |
Correct |
15 ms |
768 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
26 ms |
896 KB |
Output is correct |
5 |
Correct |
20 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
756 KB |
Output is correct |
2 |
Correct |
18 ms |
748 KB |
Output is correct |
3 |
Correct |
26 ms |
748 KB |
Output is correct |
4 |
Correct |
20 ms |
748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |