Submission #302434

# Submission time Handle Problem Language Result Execution time Memory
302434 2020-09-18T16:47:24 Z square1001 Towns (IOI15_towns) C++14
48 / 100
21 ms 896 KB
#include "towns.h"
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int hubDistance(int N, int sub) {
	if(sub == 1 || sub == 2) {
		vector<int> da(N);
		for(int i = 1; i < N; ++i) {
			da[i] = getDistance(0, i);
		}
		int ma = max_element(da.begin(), da.end()) - da.begin();
		vector<int> db(N);
		for(int i = 0; i < N; ++i) {
			if(i != ma) {
				db[i] = getDistance(ma, i);
			}
		}
		int mb = max_element(db.begin(), db.end()) - db.begin();
		int mindiff = (1 << 30);
		for(int i = 0; i < N; ++i) {
			if(i != ma && i != mb) {
				int dy = getDistance(mb, i);
				mindiff = min(mindiff, abs(db[i] - dy));
			}
		}
		return (db[mb] + mindiff) / 2;
	}
	if(sub == 3) {
		vector<vector<int> > dlist(N, vector<int>(N, -1));
		for(int i = 0; i < N; ++i) {
			for(int j = 0; j < i; ++j) {
				int res = getDistance(i, j);
				dlist[i][j] = res;
				dlist[j][i] = res;
			}
		}
		int ma = max_element(dlist[0].begin(), dlist[0].end()) - dlist[0].begin();
		int mb = max_element(dlist[ma].begin(), dlist[ma].end()) - dlist[ma].begin();
		vector<int> ds(N);
		int mindiff = (1 << 30);
		for(int i = 0; i < N; ++i) {
			ds[i] = dlist[ma][i] - dlist[mb][i];
			mindiff = min(mindiff, abs(ds[i]));
		}
		int R = (dlist[ma][mb] + mindiff) / 2;
		vector<int> depth(N);
		for(int i = 0; i < N; ++i) {
			depth[i] = (dlist[ma][i] + dlist[mb][i] - dlist[ma][mb]) / 2;
		}
		// ds[i] = mindiff pattern
		int cl1 = 0, cr1 = 0;
		for(int i = 0; i < N; ++i) {
			if(ds[i] < mindiff) ++cl1;
			if(ds[i] > mindiff) ++cr1;
		}
		int cm1 = 0;
		for(int i = 0; i < N; ++i) {
			int cnt = 0;
			for(int j = 0; j < N; ++j) {
				if(ds[i] == mindiff && ds[j] == mindiff && dlist[i][j] < depth[i] + depth[j]) {
					++cnt;
				}
			}
			cm1 = max(cnt, cm1);
		}
		if(cm1 >= 1 && cl1 <= N / 2 && cm1 <= N / 2 && cr1 <= N / 2) {
			return R;
		}
		// ds[i] = -mindiff pattern
		int cl2 = 0, cr2 = 0;
		for(int i = 0; i < N; ++i) {
			if(ds[i] < -mindiff) ++cl2;
			if(ds[i] > -mindiff) ++cr2;
		}
		int cm2 = 0;
		for(int i = 0; i < N; ++i) {
			int cnt = 0;
			for(int j = 0; j < N; ++j) {
				if(ds[i] == -mindiff && ds[j] == -mindiff && dlist[i][j] < depth[i] + depth[j]) {
					++cnt;
				}
			}
			cm2 = max(cnt, cm2);
		}
		if(cm2 >= 1 && cl2 <= N / 2 && cm2 <= N / 2 && cr2 <= N / 2) {
			return R;
		}
		return -R;
	}
	if(sub == 4) {
		vector<int> da(N);
		for(int i = 1; i < N; ++i) {
			da[i] = getDistance(0, i);
		}
		int ma = max_element(da.begin(), da.end()) - da.begin();
		vector<int> db(N);
		for(int i = 0; i < N; ++i) {
			if(i != ma) {
				db[i] = getDistance(ma, i);
			}
		}
		int mb = max_element(db.begin(), db.end()) - db.begin();
		vector<int> ds(N);
		int mindiff = (1 << 30);
		for(int i = 0; i < N; ++i) {
			int dy = getDistance(mb, i);
			ds[i] = db[i] - dy;
			mindiff = min(mindiff, abs(ds[i]));
		}
		int R = (db[mb] + mindiff) / 2;
		int cl1 = 0, cm1 = 0, cr1 = 0;
		for(int i = 0; i < N; ++i) {
			if(ds[i] < mindiff) ++cl1;
			else if(ds[i] == mindiff) ++cm1;
			else ++cr1;
		}
		if(cm1 >= 1 && cl1 <= N / 2 && cm1 <= N / 2 && cr1 <= N / 2) {
			return R;
		}
		int cl2 = 0, cm2 = 0, cr2 = 0;
		for(int i = 0; i < N; ++i) {
			if(ds[i] < -mindiff) ++cl2;
			else if(ds[i] == -mindiff) ++cm2;
			else ++cr2;
		}
		if(cm2 >= 1 && cl2 <= N / 2 && cm2 <= N / 2 && cr2 <= N / 2) {
			return R;
		}
		return -R;
	}
	return 0;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:13:46: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   13 |   int ma = max_element(da.begin(), da.end()) - da.begin();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
towns.cpp:20:46: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   20 |   int mb = max_element(db.begin(), db.end()) - db.begin();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
towns.cpp:39:58: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   39 |   int ma = max_element(dlist[0].begin(), dlist[0].end()) - dlist[0].begin();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
towns.cpp:40:60: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   40 |   int mb = max_element(dlist[ma].begin(), dlist[ma].end()) - dlist[ma].begin();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
towns.cpp:97:46: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
   97 |   int ma = max_element(da.begin(), da.end()) - da.begin();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
towns.cpp:104:46: warning: conversion from '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'} to 'int' may change value [-Wconversion]
  104 |   int mb = max_element(db.begin(), db.end()) - db.begin();
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 20 ms 384 KB Output is correct
5 Correct 20 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 384 KB Output is correct
2 Correct 15 ms 384 KB Output is correct
3 Correct 20 ms 384 KB Output is correct
4 Correct 20 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 384 KB Output is correct
2 Correct 21 ms 896 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 21 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -