結果

問題 No.5004 Room Assignment
ユーザー butsurizukibutsurizuki
提出日時 2021-11-29 18:02:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 241 ms / 5,000 ms
コード長 1,389 bytes
コンパイル時間 3,419 ms
実行使用メモリ 22,392 KB
スコア 135,964,965
平均クエリ数 7641.51
最終ジャッジ日時 2021-11-30 23:55:58
合計ジャッジ時間 32,473 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 235 ms
21,900 KB
testcase_01 AC 234 ms
21,780 KB
testcase_02 AC 239 ms
21,936 KB
testcase_03 AC 234 ms
21,900 KB
testcase_04 AC 235 ms
21,888 KB
testcase_05 AC 239 ms
21,948 KB
testcase_06 AC 233 ms
22,140 KB
testcase_07 AC 234 ms
22,128 KB
testcase_08 AC 234 ms
22,140 KB
testcase_09 AC 234 ms
21,936 KB
testcase_10 AC 234 ms
22,020 KB
testcase_11 AC 236 ms
21,984 KB
testcase_12 AC 236 ms
21,780 KB
testcase_13 AC 233 ms
21,780 KB
testcase_14 AC 233 ms
22,104 KB
testcase_15 AC 233 ms
22,128 KB
testcase_16 AC 235 ms
21,972 KB
testcase_17 AC 239 ms
22,116 KB
testcase_18 AC 237 ms
21,756 KB
testcase_19 AC 234 ms
21,912 KB
testcase_20 AC 237 ms
21,900 KB
testcase_21 AC 233 ms
21,924 KB
testcase_22 AC 239 ms
21,840 KB
testcase_23 AC 237 ms
21,936 KB
testcase_24 AC 237 ms
21,936 KB
testcase_25 AC 235 ms
21,792 KB
testcase_26 AC 237 ms
21,948 KB
testcase_27 AC 238 ms
21,972 KB
testcase_28 AC 235 ms
22,152 KB
testcase_29 AC 235 ms
21,720 KB
testcase_30 AC 236 ms
22,140 KB
testcase_31 AC 236 ms
21,948 KB
testcase_32 AC 235 ms
21,936 KB
testcase_33 AC 238 ms
22,068 KB
testcase_34 AC 234 ms
21,912 KB
testcase_35 AC 235 ms
21,920 KB
testcase_36 AC 234 ms
21,972 KB
testcase_37 AC 236 ms
21,936 KB
testcase_38 AC 235 ms
21,996 KB
testcase_39 AC 233 ms
22,104 KB
testcase_40 AC 234 ms
21,924 KB
testcase_41 AC 235 ms
21,972 KB
testcase_42 AC 234 ms
22,392 KB
testcase_43 AC 236 ms
21,900 KB
testcase_44 AC 236 ms
22,092 KB
testcase_45 AC 235 ms
22,104 KB
testcase_46 AC 234 ms
21,924 KB
testcase_47 AC 235 ms
21,948 KB
testcase_48 AC 237 ms
21,792 KB
testcase_49 AC 235 ms
21,912 KB
testcase_50 AC 234 ms
21,936 KB
testcase_51 AC 236 ms
22,128 KB
testcase_52 AC 237 ms
21,936 KB
testcase_53 AC 233 ms
21,960 KB
testcase_54 AC 237 ms
21,948 KB
testcase_55 AC 235 ms
21,936 KB
testcase_56 AC 238 ms
21,912 KB
testcase_57 AC 236 ms
21,924 KB
testcase_58 AC 237 ms
21,912 KB
testcase_59 AC 241 ms
21,936 KB
testcase_60 AC 236 ms
21,924 KB
testcase_61 AC 236 ms
22,092 KB
testcase_62 AC 236 ms
21,944 KB
testcase_63 AC 236 ms
21,780 KB
testcase_64 AC 234 ms
21,936 KB
testcase_65 AC 236 ms
21,960 KB
testcase_66 AC 235 ms
22,152 KB
testcase_67 AC 233 ms
21,744 KB
testcase_68 AC 233 ms
22,260 KB
testcase_69 AC 235 ms
21,984 KB
testcase_70 AC 236 ms
21,960 KB
testcase_71 AC 235 ms
22,140 KB
testcase_72 AC 234 ms
21,924 KB
testcase_73 AC 237 ms
21,924 KB
testcase_74 AC 234 ms
21,936 KB
testcase_75 AC 234 ms
22,028 KB
testcase_76 AC 237 ms
21,936 KB
testcase_77 AC 235 ms
21,792 KB
testcase_78 AC 234 ms
22,368 KB
testcase_79 AC 234 ms
21,948 KB
testcase_80 AC 235 ms
21,948 KB
testcase_81 AC 235 ms
21,792 KB
testcase_82 AC 234 ms
21,948 KB
testcase_83 AC 235 ms
21,824 KB
testcase_84 AC 235 ms
21,792 KB
testcase_85 AC 237 ms
21,924 KB
testcase_86 AC 234 ms
22,080 KB
testcase_87 AC 236 ms
21,968 KB
testcase_88 AC 234 ms
22,140 KB
testcase_89 AC 240 ms
22,344 KB
testcase_90 AC 236 ms
22,152 KB
testcase_91 AC 236 ms
21,828 KB
testcase_92 AC 233 ms
21,900 KB
testcase_93 AC 237 ms
22,224 KB
testcase_94 AC 236 ms
21,944 KB
testcase_95 AC 235 ms
21,984 KB
testcase_96 AC 237 ms
22,128 KB
testcase_97 AC 237 ms
21,924 KB
testcase_98 AC 240 ms
22,044 KB
testcase_99 AC 235 ms
21,960 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
  int T,R;
  cin >> T >> R;
  int p=0;
  UnionFind uf(5555);
  vector<int> S(5555);
  vector<int> ma(5555),mi(5555);
  for(int i=0;i<T;i++){
    int n;
    cin >> n;
    vector<pair<int,int>> act;
    for(int j=0;j<n;j++){
      p++;
      cin >> S[p];
      ma[p]=S[p];
      mi[p]=S[p];
      for(int k=p-1;k>=1;k--){
        if(uf.size(p)==R){break;}
        if(uf.findSet(k,p)){continue;}
        if(uf.size(k)+uf.size(p)>R){continue;}
        int rk=uf.root(k);
        int rp=uf.root(p);
        if(max(ma[rk],ma[rp])-min(mi[rk],mi[rp])>3){continue;}
        uf.unionSet(rk,rp);
        act.push_back({rk,rp});
        ma[uf.root(rk)]=max(ma[rk],ma[rp]);
        mi[uf.root(rk)]=min(mi[rk],mi[rp]);
      }
    }
    cout << act.size() << '\n';
    for(auto &nx : act){cout << nx.first << ' ' << nx.second << '\n';}
    fflush(stdout);
  }
  return 0;
}
0