이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 310;
int dist[MAXN][MAXN];
int marc[MAXN][MAXN];
int p1, p2, n;
int cnt;
int getD(int i, int j){
if(marc[i][j]) return dist[i][j];
marc[i][j] = marc[j][i] = 1;
if(i == j) return dist[i][j] = dist[j][i] = 0;
cnt++;
return dist[i][j] = dist[j][i] = getDistance(i, j);
}
int getSize(vector<int> values, int goal){
vector<multiset<int> > alive, dead;
for(int i = 0; i < values.size(); i++){
multiset<int> aux;
aux.insert(values[i]);
alive.push_back(aux);
}
int k = -1;
if(values.size() % 2 == 1){
k = values.back();
alive.pop_back();
}
while(alive.size() > 1){
if(alive.size() % 2 == 1) {
dead.push_back(alive.back());
alive.pop_back();
}
vector<multiset<int> > aux;
for(int i = 0; i < alive.size(); i += 2){
multiset<int> g1, g2;
g1 = alive[i];
g2 = alive[i + 1];
int v1 = *g1.begin(), v2 = *g2.begin();
int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2;
if(x != goal){
while(!g2.empty()){
g1.insert(*g2.begin());
g2.erase(g2.begin());
}
aux.push_back(g1);
}
else{
dead.push_back(g1);
dead.push_back(g2);
}
}
alive = aux;
}
if(alive.empty()){
if(k == -1) return 1;
multiset<int> aux;
aux.insert(k);
alive.push_back(aux);
}
else{
if(k != -1){
multiset<int> aux;
aux.insert(k);
dead.push_back(aux);
}
}
for(int i = 0; i < dead.size(); i++){
multiset<int> g1, g2;
g1 = alive[0];
g2 = dead[i];
int v1 = *g1.begin(), v2 = *g2.begin();
int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2;
if(x != goal){
while(!g2.empty()){
g1.insert(*g2.begin());
g2.erase(g2.begin());
}
alive[0] = g1;
}
}
return (alive[0].size() > n / 2) ? -1 : 1;
}
int hubDistance(int N, int sub) {
srand(time(0));
n = N;
p1 = 0, p2 = 0;
int maxi = 0;
cnt = 0;
memset(dist, 0, sizeof(dist));
memset(marc, 0, sizeof(marc));
for(int i = 0; i < N; i++){
int aux = getD(0, i);
if(aux > maxi) p1 = i, maxi = aux;
}
maxi = 0;
for(int i = 0; i < N; i++)
if(getD(p1, i) > maxi) maxi = getD(p1, i), p2 = i;
int diam = getD(p1, p2);
int cruz0 = (diam + getD(p1, 0) - getD(p2, 0)) / 2;
int ans = max(cruz0, diam - cruz0);
for(int i = 0; i < N; i++){
int x = (getD(p1, 0) + getD(p1, i) - getD(0, i)) / 2;
ans = min(ans, max(x, diam - x));
}
if(sub <= 2) return ans;
int lSize = 0, rSize = 0;
vector<int> lMid, rMid;
for(int i = 0; i < N; i++){
int x = (getD(p1, 0) + getD(p1, i) - getD(0, i)) / 2;
if(x < min(ans, diam - ans)) lSize++;
else if(x == min(ans, diam - ans)) lMid.push_back(i);
else if(x == max(ans, diam - ans)) rMid.push_back(i);
else rSize++;
}
if(lSize > N / 2 || rSize > N / 2) return -ans;
else if(lMid.size() > N / 2)
return getSize(lMid, min(ans, diam - ans)) * ans;
else if(rMid.size() > N / 2)
return getSize(rMid, max(ans, diam - ans)) * ans;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
towns.cpp: In function 'int getSize(std::vector<int>, int)':
towns.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i = 0; i < values.size(); i++){
| ~~^~~~~~~~~~~~~~~
towns.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::multiset<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i = 0; i < alive.size(); i += 2){
| ~~^~~~~~~~~~~~~~
towns.cpp:71:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::multiset<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(int i = 0; i < dead.size(); i++){
| ~~^~~~~~~~~~~~~
towns.cpp:85:26: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
85 | return (alive[0].size() > n / 2) ? -1 : 1;
| ~~~~~~~~~~~~~~~~^~~~~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:89:12: warning: conversion from 'time_t' {aka 'long int'} to 'unsigned int' may change value [-Wconversion]
89 | srand(time(0));
| ~~~~^~~
towns.cpp:125:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
125 | else if(lMid.size() > N / 2)
| ~~~~~~~~~~~~^~~~~~~
towns.cpp:127:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
127 | else if(rMid.size() > N / 2)
| ~~~~~~~~~~~~^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |