結果
| 問題 |
No.5004 Room Assignment
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-29 17:49:09 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 189 ms / 5,000 ms |
| コード長 | 1,064 bytes |
| コンパイル時間 | 2,603 ms |
| 実行使用メモリ | 22,404 KB |
| スコア | 124,207,773 |
| 平均クエリ数 | 7645.80 |
| 最終ジャッジ日時 | 2021-11-30 23:55:09 |
| 合計ジャッジ時間 | 24,838 ms |
|
ジャッジサーバーID (参考情報) |
judge10 / judge11 |
| 純コード判定しない問題か言語 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 100 |
ソースコード
#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);
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];
for(int k=p-1;k>=1;k--){
if(abs(S[k]-S[p])<=4 && uf.size(k)+uf.size(p)<=R){
act.push_back({k,p});
uf.unionSet(k,p);
}
}
}
cout << act.size() << '\n';
for(auto &nx : act){cout << nx.first << ' ' << nx.second << '\n';}
fflush(stdout);
}
return 0;
}