Submission #1014724

# Submission time Handle Problem Language Result Execution time Memory
1014724 2024-07-05T10:49:38 Z MarwenElarbi Towns (IOI15_towns) C++17
25 / 100
14 ms 1112 KB
#include <bits/stdc++.h>
#include "towns.h"
using namespace std;
int getDistance(int i, int j);
int hubDistance(int N, int sub) {
    long long mx=0;
    int one;
    for (int i = 1; i < N; ++i)
    {
        long long cur=getDistance(0,i);
        if(cur>mx){
            mx=cur;
            one=i;
        }
    }
    vector<long long> a(N,0);
    int two;
    mx=0;
    for (int i = 0; i < N; ++i)
    {
        if(i==one) continue;
        a[i]=getDistance(one,i);
        if(a[i]>mx){
            mx=a[i];
            two=i;
        }
    }
    vector<long long> b(N,0);
    for (int i = 0; i < N; ++i)
    {
        if(i==two) continue;
        b[i]=getDistance(two,i);
    }
    long long d=a[two];
    long long res=1e18;
    for (int i = 0; i < N; ++i)
    {
        if(i==one||i==two) continue;
        long long x=abs(a[i]-b[i]);
        long long r=0;
        r=max(r,(x+d)/2);
        r=max(r,d-(d+x)/2);
        res=min(res,r);
    }
    return res;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:45:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   45 |     return res;
      |            ^~~
towns.cpp:5:28: warning: unused parameter 'sub' [-Wunused-parameter]
    5 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~
towns.cpp:38:21: warning: 'two' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |         if(i==one||i==two) continue;
      |                    ~^~~~~
towns.cpp:22:25: warning: 'one' may be used uninitialized in this function [-Wmaybe-uninitialized]
   22 |         a[i]=getDistance(one,i);
      |              ~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 856 KB Output is correct
2 Correct 7 ms 852 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 9 ms 844 KB Output is correct
5 Correct 12 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 860 KB Output is correct
2 Correct 7 ms 860 KB Output is correct
3 Correct 11 ms 860 KB Output is correct
4 Correct 14 ms 984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -