結果

問題 No.168 ものさし
ユーザー TamuoTamuoTamuoTamuoTamuoTamuo
提出日時 2019-07-16 17:33:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,230 bytes
コンパイル時間 4,244 ms
コンパイル使用メモリ 173,436 KB
実行使用メモリ 15,588 KB
最終ジャッジ日時 2023-08-21 01:12:53
合計ジャッジ時間 5,306 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
6,208 KB
testcase_01 WA -
testcase_02 AC 2 ms
4,380 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,388 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 18 ms
6,392 KB
testcase_12 AC 59 ms
15,424 KB
testcase_13 AC 81 ms
15,380 KB
testcase_14 AC 81 ms
15,588 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 3 ms
4,384 KB
testcase_18 AC 6 ms
4,384 KB
testcase_19 AC 77 ms
15,376 KB
testcase_20 AC 80 ms
15,288 KB
testcase_21 AC 79 ms
15,428 KB
testcase_22 AC 79 ms
15,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/x86_64-pc-linux-gnu/bits/stdc++.h:41,
         次から読み込み:  main.cpp:1:
関数 ‘constexpr typename __gnu_cxx::__enable_if<std::__is_integer<_Tp>::__value, double>::__type std::sqrt(_Tp) [with _Tp = long long int]’ 内,
    inlined from ‘int main()’ at main.cpp:115:9:
/usr/local/gcc7/include/c++/12.2.0/cmath:476:28: 警告: ‘original’ may be used uninitialized [-Wmaybe-uninitialized]
  476 |     { return __builtin_sqrt(__x); }
      |              ~~~~~~~~~~~~~~^~~~~
main.cpp: 関数 ‘int main()’ 内:
main.cpp:105:8: 備考: ‘original’ はここで定義されています
  105 |     ll original;
      |        ^~~~~~~~

ソースコード

diff #

#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=(n); i--)
#define LREP(lst,itr) for(auto itr = lst.begin(); itr != lst.end(); ++itr)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define P(s) cout<<(s)<<endl
#define P2(a, b) cout<<(a)<<" "<<(b)<<endl
#define V2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

struct point_dist{
    ll point1;
    ll point2;
    ll dist;
};

struct points{
    ll x;
    ll y;
};

bool cmp(const point_dist& A, const point_dist& B){
    return A.dist < B.dist;
}

ll pow(ll A){
    return A*A;
}

const int MAX_N = 100010;

struct UnionFind {
	int par[MAX_N];    // 親ノードの番号
	int deph[MAX_N];   // ノードの深さ

	UnionFind(int n) {
		fill(par, par + MAX_N, -1);
		for (int i = 0; i<n; i++) {
			par[i] = i;
			deph[i] = 0;
		}
	}

	int find(int x) {
		if (par[x] == x) {
			return x;
		} else {
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			/* 同じグループに属しているときの処理
			// istree = false;
			*/
			return;
		} 
		if (deph[x] < deph[y]) {
			par[x] = par[y];
		} else {
			par[y] = par[x];
			if (deph[x] == deph[y]) deph[x]++;
		}
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

int main(){
    ll n,x,y;
    cin >> n;
    vector<points> ps(n+1);
    vector<point_dist> pd;
    REP(i,1,n+1){
        cin >> x >> y;
        ps[i].x=x;
        ps[i].y=y;
    }
    REP(i,1,n+1){
        REP(j,i+1,n+1){
            pd.push_back({i,j,pow(abs(ps[i].x-ps[j].x))+pow(abs(ps[i].y-ps[j].y))});
        }
    }
    
    /**
    for(auto item:pd){
        P2(item.point1,item.point2);
    }
    **/

    sort(pd.begin(),pd.end(),cmp);

    UnionFind uf(n);
    ll original;
    for(auto item : pd){
        uf.unite(item.point1,item.point2);
        if(uf.same(1,n)){
            original = item.dist;
            break;
        }
    }

    if(original%100==0){
        P(((ll)sqrt(original)/10)*10);
    }else{
        P(((ll)sqrt(original)/10)*10+10);
    }
     
}
0