# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1030371 |
2024-07-22T03:55:33 Z |
pcc |
Towns (IOI15_towns) |
C++17 |
|
293 ms |
1180 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;
for(int s = 0;s<N;s++){
for(int e = s+1;e<N;e++){
vector<pii> v;
int len = ask(s,e);
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:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | 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 |
293 ms |
856 KB |
Output is correct |
2 |
Correct |
177 ms |
848 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
252 ms |
1180 KB |
Output is correct |
5 |
Correct |
220 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
193 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |