結果

問題 No.1519 Diversity
ユーザー snow39snow39
提出日時 2021-05-28 20:46:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,395 bytes
コンパイル時間 1,225 ms
コンパイル使用メモリ 110,128 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 23:05:21
合計ジャッジ時間 3,674 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin>>N;
  
  //vector<vector<int>> exi_edge(N,vector<int> (N,0));
  vector<int> deg(N,0);
  vector<pair<int,int>> output;

  for(int d=1;d<N;d++){
    vector<int> cnt(d,0);
    rep(i,d) cnt[deg[i]]++;

    vector<int> used(N,0);
    rep(i,d){
      if(deg[i]==d-1){
        output.push_back(mkp(i,d));
        cnt[deg[i]]--;

        deg[i]++;
        deg[d]++;
        used[i]=1;

        cnt[deg[i]]++;
        break;
      }
    }

    for(int k=1;k+1<d;k++){
      if(cnt[k]<=1) continue;
      rep(i,d){
        if(deg[i]!=k) continue;
        if(used[i]) continue;

        output.push_back(mkp(i,d));
        cnt[deg[i]]--;

        deg[i]++;
        deg[d]++;
        used[i]=1;

        cnt[deg[i]]++;
        break;
      }
    }
  }

  cout<<output.size()<<"\n";
  for(auto [a,b]:output) cout<<a+1<<" "<<b+1<<"\n";

  return 0;
}
0