제출 #133764

#제출 시각아이디문제언어결과실행 시간메모리
133764MAMBA도시들 (IOI15_towns)C++17
35 / 100
20 ms376 KiB
#include "towns.h" #include <bits/stdc++.h> using namespace std; #define rep(i , j , k) for (int i = j; i < k; i++) typedef long long ll; template<class S, class T> inline bool smax(S &a, T b) { if (a < b) { a = b; return true; } return false; } const int MAXN = 1e3; ll D1[MAXN], D2[MAXN], f[MAXN], z[MAXN], N; int hubDistance(int N2, int sub) { N = N2; int r1 = 0; ll d = 0; rep(i , 1 , N) if (smax(d , getDistance(0 , i))) r1 = i; rep(i , 0 , N) D1[i] = getDistance(r1 , i); int r2 = max_element(D1 , D1 + N) - D1; rep(i , 0 , N) D2[i] = getDistance(r2 , i); ll limit = D1[r2]; rep(i , 0 , N) f[i] = (limit + D1[i] - D2[i]) / 2; sort(f , f + N); ll R = limit; rep(i , 0 , N) R = min(R , max(f[i] , limit - f[i])); if (sub <= 2) return R; // DONE DONE DONE DONE DONE int i1 = 0, i2 = 0; int j1 = 0, j2 = 0; rep(i , 0 , N) { if (f[i] == R) i2++; if (f[i] == limit - R) i1++; if (f[i] < limit - R) j1++; if (f[i] > R) j2++; } int n2 = N / 2; if (sub == 4) { if (j1 <= n2 && i1 <= n2 && (N - j1 - i1) <= n2) return R; if (j2 <= n2 && i2 <= n2 && (N - j2 - i2) <= n2) return R; return -R; } // DONE DONE DONE DONE DONE DONE DONE DONE rep(i , 0 , N) { z[i] = (limit + D1[i] - D2[i]) / 2; f[i] = D1[i] - z[i]; } auto check = [](ll g, int n2) -> bool { int cnt = 0; int last = -1; rep(i , 0 , N) if (z[i] == g) { if (last == -1 || getDistance(i , last) == f[i] + f[last]) { cnt--; if (cnt <= 0) { cnt = 1; last = i; } } else cnt++; } cnt = 0; rep(i , 0 , N) if (z[i] == g && getDistance(last , i) != f[i] + f[last]) cnt++; return cnt <= n2; }; if (limit == 2*R) { if (j1 <= n2 && j2 <= n2) if (check(R , n2)) return R; return -R; } if (j2 + i2 <= n2) { if (check(limit - R , n2)) return R; return -R; } if (i1 + j1 <= n2) { if (check(R , n2)) return R; } return -R; }

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:35:36: warning: conversion to 'int' from 'long int' may alter its value [-Wconversion]
  int r2 = max_element(D1 , D1 + N) - D1;
           ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
towns.cpp:52:23: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  if (sub <= 2) return R;
                       ^
towns.cpp:69:13: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  int n2 = N / 2;
           ~~^~~
towns.cpp:72:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
    return R;
           ^
towns.cpp:74:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
    return R;
           ^
towns.cpp:75:10: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   return -R;
          ^~
towns.cpp: In lambda function:
towns.cpp:86:35: warning: declaration of 'n2' shadows a previous local [-Wshadow]
  auto check = [](ll g, int n2) -> bool {
                                   ^~~~
towns.cpp:69:6: note: shadowed declaration is here
  int n2 = N / 2;
      ^~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:112:12: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
     return R;
            ^
towns.cpp:113:10: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   return -R;
          ^~
towns.cpp:117:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
    return R;
           ^
towns.cpp:118:10: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
   return -R;
          ^~
towns.cpp:122:11: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
    return R;
           ^
towns.cpp:125:9: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
  return -R;
         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...