結果

問題 No.168 ものさし
ユーザー nebukuro09nebukuro09
提出日時 2016-09-27 14:59:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,801 bytes
コンパイル時間 521 ms
コンパイル使用メモリ 39,680 KB
実行使用メモリ 10,864 KB
最終ジャッジ日時 2024-05-01 05:42:35
合計ジャッジ時間 3,981 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 65 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 484 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 681 ms
5,376 KB
testcase_08 AC 437 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 96 ms
5,376 KB
testcase_16 AC 80 ms
5,376 KB
testcase_17 AC 71 ms
5,376 KB
testcase_18 AC 42 ms
5,376 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:58:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
   58 |     scanf("%d", &x[i]);
      |            ~^   ~~~~~
      |             |   |
      |             |   long long int*
      |             int*
      |            %lld
main.cpp:59:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=]
   59 |     scanf("%d", &y[i]);
      |            ~^   ~~~~~
      |             |   |
      |             |   long long int*
      |             int*
      |            %lld
main.cpp:56:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   56 |   scanf("%d", &N);
      |   ~~~~~^~~~~~~~~~
main.cpp:58:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   58 |     scanf("%d", &x[i]);
      |     ~~~~~^~~~~~~~~~~~~
main.cpp:59:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   59 |     scanf("%d", &y[i]);
      |     ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <vector>

class UnionFind {
private:
  std::vector<int> table;
public:
  UnionFind(int n) {
    table = std::vector<int> (n, -1);
  }
  
  ~UnionFind(){};
  
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (table[x] >= table[y]) {
      table[y] += table[x];
      table[x] = y;
    } else {
      table[x] += table[y];
      table[y] = x;
    }
  }

  int find(int x) {
    if (table[x] < 0) return x;
    return table[x] = find(table[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }
};

int N;
long long int dists[1001][1001];
long long int f(long long int x0, long long int y0, long long int x1, long long int y1) {
  return (x0-x1)*(x0-x1) + (y0-y1)*(y0-y1);
}
bool ok(long long int m) {
  UnionFind uf = UnionFind(N);
  for (int i = 0; i < N; i++)
    for (int j = i+1; j < N; j++)
      if (dists[i][j] <= m)
	uf.unite(i, j);
  return uf.find(0) == uf.find(N-1);
}
long long int sqrtint(long long int n) {
  long long int i;
  for (i = 0; n > 0; i++)
    n -= i * 2 + 1;
  return i-1;
}
  
int main() {
  long long int x[1000];
  long long int y[1000];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &x[i]);
    scanf("%d", &y[i]);
  }

  long long int high = 1000000000000000000*2;
  long long int low = 0;
  long long int  middle;

  for (int i = 0; i < N; i++) 
    for (int j = i+1; j < N; j++)
      dists[i][j] = f(x[i], y[i], x[j], y[j]);

  while (high-low > 1) {
    middle = (high+low)/2;
    if (ok(middle))
      high = middle;
    else
      low = middle;
  }

  if (!ok(high))
    high = low;
  long long int sqrt = sqrtint(high);
  if (sqrt*sqrt < high)
    sqrt++;

  int ans = sqrt/10*10;
  if (sqrt%10 > 0)
    ans += 10;
  printf("%d\n", ans);
  return 0;
}
0