結果
問題 | No.5004 Room Assignment |
ユーザー | siman |
提出日時 | 2021-12-01 04:47:28 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 154 ms / 5,000 ms |
コード長 | 3,221 bytes |
コンパイル時間 | 1,549 ms |
実行使用メモリ | 22,380 KB |
スコア | 137,681,296 |
平均クエリ数 | 7643.20 |
最終ジャッジ日時 | 2021-12-01 04:47:50 |
合計ジャッジ時間 | 20,924 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 136 ms
21,924 KB |
testcase_01 | AC | 138 ms
21,936 KB |
testcase_02 | AC | 139 ms
21,912 KB |
testcase_03 | AC | 137 ms
22,152 KB |
testcase_04 | AC | 138 ms
22,212 KB |
testcase_05 | AC | 146 ms
21,948 KB |
testcase_06 | AC | 147 ms
21,960 KB |
testcase_07 | AC | 137 ms
21,780 KB |
testcase_08 | AC | 136 ms
22,152 KB |
testcase_09 | AC | 136 ms
21,792 KB |
testcase_10 | AC | 136 ms
22,032 KB |
testcase_11 | AC | 136 ms
21,768 KB |
testcase_12 | AC | 136 ms
21,804 KB |
testcase_13 | AC | 135 ms
21,960 KB |
testcase_14 | AC | 135 ms
21,936 KB |
testcase_15 | AC | 146 ms
22,200 KB |
testcase_16 | AC | 138 ms
21,984 KB |
testcase_17 | AC | 138 ms
21,896 KB |
testcase_18 | AC | 135 ms
21,780 KB |
testcase_19 | AC | 138 ms
21,900 KB |
testcase_20 | AC | 136 ms
22,016 KB |
testcase_21 | AC | 136 ms
22,152 KB |
testcase_22 | AC | 138 ms
21,948 KB |
testcase_23 | AC | 134 ms
21,804 KB |
testcase_24 | AC | 154 ms
21,936 KB |
testcase_25 | AC | 134 ms
21,912 KB |
testcase_26 | AC | 134 ms
21,924 KB |
testcase_27 | AC | 135 ms
21,972 KB |
testcase_28 | AC | 134 ms
21,792 KB |
testcase_29 | AC | 134 ms
21,908 KB |
testcase_30 | AC | 134 ms
21,936 KB |
testcase_31 | AC | 135 ms
21,780 KB |
testcase_32 | AC | 135 ms
21,960 KB |
testcase_33 | AC | 154 ms
21,792 KB |
testcase_34 | AC | 143 ms
21,936 KB |
testcase_35 | AC | 140 ms
22,148 KB |
testcase_36 | AC | 138 ms
22,116 KB |
testcase_37 | AC | 136 ms
21,972 KB |
testcase_38 | AC | 134 ms
21,948 KB |
testcase_39 | AC | 136 ms
21,792 KB |
testcase_40 | AC | 136 ms
21,936 KB |
testcase_41 | AC | 137 ms
22,176 KB |
testcase_42 | AC | 148 ms
22,152 KB |
testcase_43 | AC | 137 ms
21,984 KB |
testcase_44 | AC | 135 ms
22,152 KB |
testcase_45 | AC | 134 ms
21,996 KB |
testcase_46 | AC | 139 ms
22,368 KB |
testcase_47 | AC | 140 ms
21,912 KB |
testcase_48 | AC | 135 ms
21,948 KB |
testcase_49 | AC | 135 ms
21,936 KB |
testcase_50 | AC | 135 ms
21,948 KB |
testcase_51 | AC | 150 ms
22,152 KB |
testcase_52 | AC | 146 ms
21,936 KB |
testcase_53 | AC | 136 ms
21,984 KB |
testcase_54 | AC | 137 ms
21,936 KB |
testcase_55 | AC | 134 ms
21,792 KB |
testcase_56 | AC | 134 ms
21,948 KB |
testcase_57 | AC | 136 ms
21,900 KB |
testcase_58 | AC | 135 ms
21,900 KB |
testcase_59 | AC | 135 ms
22,104 KB |
testcase_60 | AC | 143 ms
21,984 KB |
testcase_61 | AC | 145 ms
21,792 KB |
testcase_62 | AC | 135 ms
22,032 KB |
testcase_63 | AC | 137 ms
21,924 KB |
testcase_64 | AC | 137 ms
22,152 KB |
testcase_65 | AC | 138 ms
21,792 KB |
testcase_66 | AC | 135 ms
21,804 KB |
testcase_67 | AC | 138 ms
21,972 KB |
testcase_68 | AC | 137 ms
21,792 KB |
testcase_69 | AC | 135 ms
22,380 KB |
testcase_70 | AC | 146 ms
21,936 KB |
testcase_71 | AC | 138 ms
21,936 KB |
testcase_72 | AC | 137 ms
21,888 KB |
testcase_73 | AC | 136 ms
21,960 KB |
testcase_74 | AC | 136 ms
22,128 KB |
testcase_75 | AC | 134 ms
22,044 KB |
testcase_76 | AC | 134 ms
21,792 KB |
testcase_77 | AC | 134 ms
21,912 KB |
testcase_78 | AC | 136 ms
21,960 KB |
testcase_79 | AC | 145 ms
21,960 KB |
testcase_80 | AC | 141 ms
22,356 KB |
testcase_81 | AC | 135 ms
21,924 KB |
testcase_82 | AC | 135 ms
21,936 KB |
testcase_83 | AC | 135 ms
22,128 KB |
testcase_84 | AC | 133 ms
21,900 KB |
testcase_85 | AC | 136 ms
21,912 KB |
testcase_86 | AC | 136 ms
22,088 KB |
testcase_87 | AC | 138 ms
21,984 KB |
testcase_88 | AC | 145 ms
21,912 KB |
testcase_89 | AC | 143 ms
21,912 KB |
testcase_90 | AC | 140 ms
21,780 KB |
testcase_91 | AC | 140 ms
21,780 KB |
testcase_92 | AC | 139 ms
21,912 KB |
testcase_93 | AC | 133 ms
22,020 KB |
testcase_94 | AC | 136 ms
22,152 KB |
testcase_95 | AC | 137 ms
22,080 KB |
testcase_96 | AC | 137 ms
21,780 KB |
testcase_97 | AC | 147 ms
22,224 KB |
testcase_98 | AC | 145 ms
22,140 KB |
testcase_99 | AC | 136 ms
22,092 KB |
ソースコード
#include <cassert> #include <cmath> #include <algorithm> #include <iostream> #include <iomanip> #include <climits> #include <map> #include <queue> #include <set> #include <cstring> #include <vector> using namespace std; typedef long long ll; class UnionFind { public: vector<int> parent; vector<int> _size; UnionFind(int n) { for (int i = 0; i < n; ++i) { parent.push_back(i); _size.push_back(1); } } int find(int x) { if (parent[x] == x) { return x; } else { return parent[x] = find(parent[x]); } } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) return; if (x > y) { parent[x] = y; _size[y] += _size[x]; } else { parent[y] = x; _size[x] += _size[y]; } } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return _size[find(x)]; } }; int T, R; struct Command { int u; int v; Command(int u = -1, int v = -1) { this->u = u; this->v = v; } string to_str() { return to_string(u) + " " + to_string(v); } }; class Adv2021 { public: void run() { int N; int id = 1; int counter[101]; memset(counter, 0, sizeof(counter)); vector<int> started_at(5555, 9999); vector<int> skills[101]; UnionFind uf(5555); vector<int> power(5555, 0); for (int t = 0; t < T; ++t) { cin >> N; vector<int> S(N); vector <Command> commands; for (int i = 0; i < N; ++i) { int s; cin >> s; S[i] = s; power[id] = s; skills[s].push_back(id); started_at[id] = t; int u = skills[s].back(); int diff = 2; if (abs(s - 50) >= 25) diff = 3; if (abs(s - 50) >= 40) diff = 5; int max_time = -1; int min_time = 9999; int best_v = -1; for (int ns = max(0, s - diff); ns <= min(100, s + diff); ++ns) { if (skills[ns].empty()) continue; for (int v : skills[ns]) { int size = uf.size(u) + uf.size(v); int time = t - started_at[v]; if (not uf.same(u, v) && size <= R && max_time < time) { max_time = time; best_v = v; } } } if (best_v != -1) { uf.unite(u, best_v); started_at[uf.find(u)] = min(started_at[u], started_at[best_v]); started_at[uf.find(best_v)] = min(started_at[u], started_at[best_v]); commands.push_back(Command(u, best_v)); } counter[s]++; id++; } cout << commands.size() << endl; for (Command &cmd : commands) { cout << cmd.to_str() << endl; } cout << flush; } vector<bool> checked(5555, false); for (int i = 1; i < id; ++i) { int p = uf.find(i); if (checked[p]) continue; if (uf.size(p) == R) continue; checked[p] = true; fprintf(stderr, "x: %d, size: %d, st: %d\n", power[p], uf.size(p), started_at[p]); } for (int x = 0; x <= 100; ++x) { // fprintf(stderr, "x: %d, cnt: %d\n", x, counter[x]); } } }; int main() { cin >> T >> R; Adv2021 solver; solver.run(); return 0; }