Submission #331030

# Submission time Handle Problem Language Result Execution time Memory
331030 2020-11-27T04:47:48 Z IloveN Towns (IOI15_towns) C++14
35 / 100
23 ms 748 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 x : vt)
    {
        int cnt=0;
        for (int y : vt)
            if (get(x,y)<dis[s][x]-lc[x]+dis[s][y]-lc[y]) 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:53:14: warning: declaration of 'int x' shadows a parameter [-Wshadow]
   53 |     for (int x : vt)
      |              ^
towns.cpp:42:31: note: shadowed declaration is here
   42 | bool check_balance(vi &lc,int x,int n,int sub,int s,int t)
      |                           ~~~~^
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 23 ms 748 KB Output is correct
2 Correct 16 ms 748 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 21 ms 748 KB Output is correct
5 Correct 21 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 748 KB Output is correct
2 Correct 17 ms 748 KB Output is correct
3 Correct 21 ms 748 KB Output is correct
4 Correct 21 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 748 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 4 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -