結果

問題 No.168 ものさし
ユーザー izuru_matsuura
提出日時 2016-08-30 21:25:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,924 bytes
コンパイル時間 1,460 ms
コンパイル使用メモリ 154,184 KB
最終ジャッジ日時 2025-03-13 06:55:11
合計ジャッジ時間 2,230 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In instantiation of ‘std::istream& {anonymous}::operator>>(std::istream&, std::vector<_Tp>&) [with T = std::pair<int, int>; std::istream = std::basic_istream<char>]’:
main.cpp:28:29:   required from here
main.cpp:17:61: error: no match for ‘operator>>’ (operand types are ‘std::istream’ {aka ‘std::basic_istream<char>’} and ‘std::pair<int, int>’)
   17 |         for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
      |                                                          ~~~^~~~~~
In file included from /usr/include/c++/13/sstream:40,
                 from /usr/include/c++/13/complex:45,
                 from /usr/include/c++/13/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:127,
                 from main.cpp:1:
/usr/include/c++/13/istream:325:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’
  325 |       operator>>(void*& __p)
      |       ^~~~~~~~
/usr/include/c++/13/istream:325:25: note:   no known conversion for argument 1 from ‘std::pair<int, int>’ to ‘void*&’
  325 |       operator>>(void*& __p)
      |                  ~~~~~~~^~~
/usr/include/c++/13/istream:224:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char; _Traits = std::char_traits<char>; __istream_type = std::basic_istream<char>]’
  224 |       operator>>(long double& __f)
      |       ^~~~~~~~
/usr/include/c++/13/istream:224:31: note:   no known conversion for argument 1 from ‘std::pair<int, int>’ to ‘long double&’
  224 |       operator>>(long double& __f)
      |                  ~~~~~~~~~~~~~^~~
/usr/include/c++/13/istream:220:7: note: candidate: ‘std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace {

    typedef long double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }
    template<class T> istream& operator>>(istream& is, pair<T,T>& p) {
        return is >> p.first >> p.second;
    }

    int N;
    vector<pair<int,int>> P;
    void input() {
        cin >> N;
        P.resize(N); cin >> P;
    }

    ll dist2(pair<int,int> a, pair<int,int> b) {
        ll dx = a.first - b.first;
        ll dy = a.second - b.second;
        return dx*dx + dy*dy;
    }

    struct UnionFind {
        vector<int> P;
        UnionFind(int N) : P(N, -1) {}
        int root(int x) {
            if (P[x] < 0) return x;
            return P[x] = root(P[x]);
        }
        void merge(int x, int y) {
            x = root(x); y = root(y);
            if (x == y) return;
            P[x] = y;
        }
        bool query(int x, int y) {
            return root(x) == root(y);
        }
    };

    bool C(ll r) {
        UnionFind uf(N);
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                if (dist2(P[i], P[j]) <= r*r) {
                    uf.merge(i, j);
                }
            }
        }
        return uf.query(0, N - 1);
    }

    void solve() {
        ll lb = 0, ub = ll(2e9);
        for (int i = 0; i < 200; i++) {
            ll mid = (lb + ub) / 2LL;
            (C(mid) ? ub : lb) = mid;
        }
        cout << (ub + 9) / 10 * 10 << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

0