結果
| 問題 |
No.168 ものさし
|
| ユーザー |
|
| 提出日時 | 2016-09-27 14:59:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,801 bytes |
| コンパイル時間 | 374 ms |
| コンパイル使用メモリ | 39,520 KB |
| 実行使用メモリ | 10,112 KB |
| 最終ジャッジ日時 | 2024-11-21 07:16:27 |
| 合計ジャッジ時間 | 4,209 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 WA * 9 |
コンパイルメッセージ
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]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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;
}