結果

問題 No.1265 Balloon Survival
ユーザー tnakao0123tnakao0123
提出日時 2020-10-24 19:38:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 94,012 KB
実行使用メモリ 11,576 KB
最終ジャッジ日時 2023-09-28 20:41:42
合計ジャッジ時間 2,932 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 7 ms
4,484 KB
testcase_15 AC 6 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 27 ms
9,676 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 4 ms
4,376 KB
testcase_20 AC 7 ms
4,552 KB
testcase_21 AC 14 ms
5,504 KB
testcase_22 AC 9 ms
4,804 KB
testcase_23 AC 10 ms
4,804 KB
testcase_24 AC 53 ms
11,244 KB
testcase_25 AC 52 ms
11,368 KB
testcase_26 AC 52 ms
11,304 KB
testcase_27 AC 52 ms
11,560 KB
testcase_28 AC 52 ms
11,276 KB
testcase_29 AC 52 ms
11,576 KB
testcase_30 AC 53 ms
11,380 KB
testcase_31 AC 52 ms
11,360 KB
testcase_32 AC 52 ms
11,384 KB
testcase_33 AC 52 ms
11,308 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 1265.cc:  No.1265 Balloon Survival - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_M = MAX_N * (MAX_N - 1) / 2;

/* typedef */

typedef long long ll;

struct Trpl {
  ll d;
  int i, j;
  Trpl() {}
  Trpl(ll _d, int _i, int _j): d(_d), i(_i), j(_j) {}

  bool operator<(const Trpl &t) const { return d < t.d; }

  void print() { printf("%lld:%d,%d\n", d, i, j); }
};

/* global variables */

int xs[MAX_N], ys[MAX_N];
Trpl ts[MAX_M];
bool used[MAX_N];

/* subroutines */

inline ll dist2(int i, int j) {
  int dx = xs[j] - xs[i], dy = ys[j] - ys[i];
  return (ll)dx * dx + (ll)dy * dy;
}

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d%d", xs + i, ys + i);

  int m = 0;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      ts[m++] = Trpl(dist2(i, j), i, j);
  sort(ts, ts + m);

  int c = 0;
  for (int k = 0; k < m; k++) {
    //ts[k].print();
    int i = ts[k].i, j = ts[k].j;
    if (i == 0) {
      if (! used[j]) used[j] = true, c++;
    }
    else {
      if (! used[i] && ! used[j])
	used[i] = used[j] = true;
    }
  }

  printf("%d\n", c);
  return 0;
}
0