Submission #1030473

# Submission time Handle Problem Language Result Execution time Memory
1030473 2024-07-22T05:35:33 Z pcc Towns (IOI15_towns) C++17
25 / 100
12 ms 348 KB
#include "towns.h"
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,popcnt,sse4")
using namespace std;

const int mxn = 120;
#define pii pair<int,int>
#define fs first
#define sc second

int dp[mxn][mxn];

int ask(int a,int b){
	if(a == b)return dp[a][b] = 0;
	if(dp[a][b] != -1)return dp[a][b];
	else return dp[a][b] = dp[b][a] = getDistance(a,b);
}

int tocen(int a,int b,int c){
	return ((ask(a,b)+ask(a,c)-ask(b,c))>>1);
}

int hubDistance(int N, int sub) {
	memset(dp,-1,sizeof(dp));
	int ans = 1e9;
	int s = 0,e = 0;
	for(int i = 1;i<N;i++){
		if(ask(s,i)>ask(s,e))e = i;
	}
	s = e;
	for(int i = 0;i<N;i++){
		if(i == s)continue;
		if(ask(s,i)>ask(s,e))e = i;
	}
	vector<pii> v;
	int len = ask(s,e);
	cerr<<"[s,e]: "<<s<<' '<<e<<endl;
	for(int i = 0;i<N;i++){
		if(i == s||i == e)continue;
		int d1 = tocen(s,i,e);
		int d2 = tocen(e,i,s);
		assert(d1+d2 == len);
		int d3 = tocen(i,s,e);
		v.push_back(pii(d1,d3));
	}
	sort(v.begin(),v.end());
	vector<pii> vv;
	for(auto &i:v){
		if(!vv.empty()&&vv.back().fs == i.fs)vv.back().sc = max(vv.back().sc,i.sc);
		else vv.push_back(i);
	}
	v.swap(vv);
	//cerr<<s<<' '<<e<<":";for(auto &j:v)cerr<<j.fs<<','<<j.sc<<' ';cerr<<endl;
	vector<int> mx(v.size(),0);
	int pref = 0;
	for(int i = 0;i<v.size();i++){
		mx[i] = max({mx[i],v[i].sc,v[i].fs+pref});
		pref = max(pref,-v[i].fs+v[i].sc);
	}
	int suf = len;
	for(int i = (int)v.size()-1;i>=0;i--){
		mx[i] = max({mx[i],suf-v[i].fs,v[i].sc});
		suf = max(suf,v[i].fs+v[i].sc);
	}
	ans = min(ans,*min_element(mx.begin(),mx.end()));
	//cerr<<s<<' '<<e<<":"<<ans<<endl;
	return -ans;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |  for(int i = 0;i<v.size();i++){
      |                ~^~~~~~~~~
towns.cpp:24:28: warning: unused parameter 'sub' [-Wunused-parameter]
   24 | int hubDistance(int N, int sub) {
      |                        ~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 348 KB Output is correct
2 Correct 8 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 9 ms 348 KB Output is correct
5 Correct 9 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 348 KB Output is correct
2 Correct 8 ms 344 KB Output is correct
3 Correct 10 ms 348 KB Output is correct
4 Correct 11 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -