結果

問題 No.1519 Diversity
ユーザー PercevalPerceval
提出日時 2021-06-04 20:32:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,834 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 70,144 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 00:00:51
合計ジャッジ時間 2,377 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 28 ms
5,376 KB
testcase_04 AC 60 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 77 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 12 ms
5,376 KB
testcase_09 AC 29 ms
5,376 KB
testcase_10 AC 52 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 72 ms
5,376 KB
testcase_13 AC 79 ms
5,376 KB
testcase_14 AC 80 ms
5,376 KB
testcase_15 AC 78 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique(データ構造をマージするテク.小を大にくっつける)
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
int main(){
  int n;
  cin>>n;
  if(n%2==0){
    cout<<n*n/4<<endl;
    for(int i=2;i<=n;i+=2){
      for(int j=1;j<i;j++){
        cout<<i<<' '<<j<<endl;
      }
    }
  }
  else{
    cout<<(n*n-1)/4<<endl;
    for(int i=3;i<=n;i+=2){
      for(int j=1;j<i;j++){
        cout<<i<<' '<<j<<endl;
      }
    }
  }
}
0