Submission #1025375

# Submission time Handle Problem Language Result Execution time Memory
1025375 2024-07-17T01:01:34 Z vjudge1 Towns (IOI15_towns) C++17
48 / 100
15 ms 1116 KB
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
int Ddis[201][201];
inline int getD(int a,int b){
    if(a==b)return 0;
    if(a>b)swap(a,b);
    if(Ddis[a][b])
        return Ddis[a][b];
    return Ddis[a][b]=getDistance(a,b);
}
mt19937 rng(random_device{}());
bool samesub(pair<int,int>a,pair<int,int>b){
    auto[i1,d1]=a;
    auto[i2,d2]=b;
    return getD(i1,i2)<d1+d2;
}
int ok(map<int,vector<pair<int,int>>>mp,int pivot,int sub){
    int toleft=0,toright=0,tot=0;
    vector<pair<int,int>> Tis;
    for(auto [i,x]:mp){tot+=x.size();
        if(i<pivot) toleft+=x.size();
        else if(i==pivot) Tis=x;
        else toright+=x.size();}
    if(toleft>tot/2||toright>tot/2)
        return 0;
    if(Tis.size()<=tot/2)
        return 1;
    if(!sub) return 0;
    vector<pair<int,pair<int,int>>> STUF;
    for(auto i:Tis){
        int has=0;
        for(auto&[q,w]:STUF)
            if(samesub(i,w))
                has=1,q++;
        if(!has)STUF.push_back({1,i});
    }
    for(auto[s,k]:STUF)
        if(s>tot/2)
            return 0;
    return 1;
}
int hubDistance(int N, int sub) {
    memset(Ddis,0,sizeof Ddis);
    int pivot=rng()%N;
    int farnod=pivot,fardis=0;
    for(int i=0;i<N;i++)
        if(getD(i,pivot)>fardis)
            farnod=i,fardis=getD(i,pivot);
    fardis=0;
    int X=farnod;
    for(int i=0;i<N;i++)
        if(getD(i,X)>fardis)
            farnod=i,fardis=getD(i,X);
    int Y=farnod,K=fardis;
    map<int,vector<pair<int,int>>> mp;
    mp[0].push_back({X,0}),mp[2*K].push_back({Y,0});
    for(int i=0;i<N;i++){
        if(i==X||i==Y)continue;
        int toX=getD(X,i),toY=getD(Y,i);
        int dep=(toX+toY-K)/2;
        int distofP=K+toX-toY;
        mp[distofP].push_back({i,dep});
    }
    int candidate2=mp.lower_bound(K)->first,candidate1=(--mp.lower_bound(K))->first;
    int R;
    if(K-candidate1<candidate2-K){
        R=K-candidate1/2;
        if(!ok(mp,candidate1,sub&1))
            R=-R;
    } else if(K-candidate1>candidate2-K){
        R=candidate2/2;
        if(!ok(mp,candidate2,sub&1))
            R=-R;
    } else {
        R=candidate2/2;
        if(!ok(mp,candidate1,sub&1)&&
            !ok(mp,candidate2,sub&1))
            R=-R;
    }
    return R;
}

Compilation message

towns.cpp: In function 'int ok(std::map<int, std::vector<std::pair<int, int> > >, int, int)':
towns.cpp:21:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   21 |     for(auto [i,x]:mp){tot+=x.size();
      |                                    ^
towns.cpp:22:36: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   22 |         if(i<pivot) toleft+=x.size();
      |                                    ^
towns.cpp:24:30: warning: conversion from 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   24 |         else toright+=x.size();}
      |                              ^
towns.cpp:27:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   27 |     if(Tis.size()<=tot/2)
      |        ~~~~~~~~~~^~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:45:20: warning: conversion from 'std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
   45 |     int pivot=rng()%N;
      |               ~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 600 KB Output is correct
2 Correct 8 ms 1116 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 10 ms 1116 KB Output is correct
5 Correct 10 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 604 KB Output is correct
2 Correct 8 ms 1116 KB Output is correct
3 Correct 11 ms 1116 KB Output is correct
4 Correct 10 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 600 KB Output is correct
2 Correct 15 ms 1024 KB Output is correct
3 Correct 0 ms 604 KB Output is correct
4 Correct 10 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -