QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116054 | #5280. Depot Rearrangement | hos_lyric# | 46 | 28ms | 27008kb | C++14 | 3.2kb | 2023-06-28 08:27:04 | 2024-05-31 14:20:01 |
Judging History
answer
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using Int = long long;
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
vector<int> uf;
int root(int u) {
return (uf[u] < 0) ? u : (uf[u] = root(uf[u]));
}
bool connect(int u, int v) {
u = root(u);
v = root(v);
if (u == v) return false;
if (uf[u] > uf[v]) swap(u, v);
uf[u] += uf[v];
uf[v] = u;
return true;
}
int N, M;
int A[410][410];
int V;
vector<vector<pair<int, int>>> graph;
vector<pair<int, int>> es;
void dfs(int u) {
for (; !graph[u].empty(); ) {
const auto e = graph[u].back();
graph[u].pop_back();
dfs(e.first);
es.push_back(e);
}
}
int main() {
for (; ~scanf("%d%d", &N, &M); ) {
for (int u = 0; u < N; ++u) for (int i = 0; i < M; ++i) {
scanf("%d", &A[u][i]);
--A[u][i];
}
int ans = 0;
V = N + M;
graph.assign(V, {});
for (int u = 0; u < N; ++u) {
vector<int> freq(M, 0);
for (int i = 0; i < M; ++i) {
const int a = A[u][i];
if (++freq[a] > 1) {
++ans;
graph[u].emplace_back(N + a, u * M + i);
}
}
for (int a = 0; a < M; ++a) if (freq[a] == 0) {
graph[N + a].emplace_back(u, -1);
}
}
uf.assign(V, -1);
for (int u = 0; u < V; ++u) {
for (const auto &e : graph[u]) {
connect(u, e.first);
}
}
vector<int> has(V, 0);
for (int u = 0; u < V; ++u) {
for (const auto &e : graph[u]) {
has[root(u)] = 1;
}
}
for (int r = 0; r < V; ++r) if (uf[r] < 0) {
if (has[r]) {
++ans;
}
}
printf("%d\n", ans);
auto oper = [&](int pos0, int pos1) -> void {
printf("%d %d\n", pos0 + 1, pos1 + 1);
};
for (int u = 0; u < V; ++u) {
es.clear();
dfs(u);
if (!es.empty()) {
reverse(es.begin(), es.end());
// cerr<<"es = "<<es<<endl;
int pos = N * M;
for (const auto &e : es) if (~e.second) {
oper(e.second, pos);
pos = e.second;
}
oper(N * M, pos);
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 4092kb
input:
10 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3
output:
0
result:
ok both subtasks are correct!
Test #2:
score: 5
Accepted
time: 0ms
memory: 3744kb
input:
5 4 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
output:
13 4 21 20 4 12 20 19 12 8 19 18 8 3 18 15 3 7 15 14 7 2 14 10 2 21 10
result:
ok both subtasks are correct!
Test #3:
score: 2
Acceptable Answer
time: 0ms
memory: 4088kb
input:
10 10 8 10 10 3 7 3 5 6 1 4 3 8 2 9 1 8 4 2 7 3 10 7 9 2 1 10 10 9 1 2 9 7 4 5 2 9 10 5 7 6 6 8 6 8 4 2 9 1 2 8 6 1 4 2 2 1 5 6 3 10 10 7 9 4 8 9 8 2 5 6 4 3 1 6 3 3 10 7 7 5 3 6 8 5 9 4 6 7 9 4 10 5 3 4 5 1 1 7 8 5
output:
32 6 101 67 6 79 67 58 79 100 58 50 100 56 50 90 56 30 90 97 30 66 97 95 66 29 95 39 29 49 39 89 49 76 89 44 76 38 44 20 38 36 20 55 36 75 55 28 75 3 28 87 3 27 87 43 27 16 43 26 16 18 26 101 18
result:
points 0.40 first subtask is correct but plan is wrong.
Test #4:
score: 2
Acceptable Answer
time: 0ms
memory: 4028kb
input:
100 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 9 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10...
output:
19 109 1001 949 109 819 949 713 819 734 713 850 734 670 850 830 670 210 830 175 210 775 175 359 775 814 359 184 814 453 184 1001 453 707 1001 747 707 1001 747
result:
points 0.40 first subtask is correct but plan is wrong.
Test #5:
score: 2
Acceptable Answer
time: 1ms
memory: 4160kb
input:
200 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
195 273 20001 2648 273 16173 2648 16885 16173 19298 16885 19398 19298 18899 19398 9994 18899 17774 9994 7068 17774 18968 7068 4495 18968 4895 4495 4482 4895 19682 4482 19198 19682 17199 19198 6599 17199 18491 6599 18091 18491 18488 18091 10488 18488 18466 10488 18966 18466 16367 18966 17266 16367 15...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #6:
score: 2
Acceptable Answer
time: 1ms
memory: 4432kb
input:
201 20 20 18 5 5 1 7 8 17 12 10 20 12 13 19 16 2 9 8 20 20 19 10 17 20 9 11 15 17 9 2 3 4 17 10 7 20 7 19 17 11 20 2 1 13 11 9 11 6 10 8 11 3 2 16 9 15 16 12 13 6 5 13 4 13 3 8 20 18 10 3 14 1 11 20 17 17 2 11 20 1 4 10 3 3 9 13 7 10 19 16 14 16 9 19 14 15 12 9 20 12 2 19 18 2 7 7 2 12 10 8 20 18 16...
output:
1401 20 4021 4000 20 3920 4000 4020 3920 3960 4020 3918 3960 3957 3918 4016 3957 3980 4016 3999 3980 3917 3999 3940 3917 3979 3940 3800 3979 4015 3800 3978 4015 3760 3978 4013 3760 3994 4013 3936 3994 3658 3936 3955 3658 3935 3955 3992 3935 3915 3992 3860 3915 3914 3860 3932 3914 3899 3932 3858 3899...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #7:
score: 2
Acceptable Answer
time: 4ms
memory: 4280kb
input:
300 300 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
205 1262 90001 72733 1262 75843 72733 77677 75843 87877 77677 51995 87877 6695 51995 64122 6695 40757 64122 38351 40757 41351 38351 38357 41351 40722 38357 63995 40722 46712 63995 84512 46712 46595 84512 51930 46595 68242 51930 83209 68242 81409 83209 83192 81409 47363 83192 7031 47363 78731 7031 71...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #8:
score: 2
Acceptable Answer
time: 3ms
memory: 6540kb
input:
301 40 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
11624 40 12041 12040 40 11720 12040 12039 11720 11680 12039 12000 11680 11640 12000 11960 11640 11600 11960 11920 11600 11560 11920 11880 11560 11520 11880 11840 11520 11480 11840 11800 11480 11440 11800 11400 11440 12038 11400 11399 12038 11999 11399 11360 11999 11959 11360 11320 11959 11919 11320 ...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #9:
score: 2
Acceptable Answer
time: 0ms
memory: 7236kb
input:
400 100 11 65 1 79 15 18 79 46 9 30 71 53 58 55 94 73 39 16 6 91 49 30 23 30 28 81 90 48 97 54 79 30 94 18 42 77 44 36 5 48 55 97 79 36 41 59 79 71 32 59 3 10 63 52 44 41 9 46 31 31 56 87 60 80 12 51 15 78 41 65 95 34 29 83 46 64 37 53 98 17 41 45 36 73 20 53 48 80 57 54 57 72 39 56 98 6 10 78 11 72...
output:
14592 100 40001 39000 100 39799 39000 39699 39799 40000 39699 39797 40000 39600 39797 39998 39600 39596 39998 39900 39596 39997 39900 39795 39997 39499 39795 39996 39499 39899 39996 39995 39899 39898 39995 39994 39898 39698 39994 39794 39698 39697 39794 39793 39697 39400 39793 39896 39400 39993 3989...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #10:
score: 2
Acceptable Answer
time: 1ms
memory: 4216kb
input:
40 160 17 2 3 4 5 6 7 91 9 10 154 12 103 14 15 16 17 25 19 58 21 8 23 24 52 26 27 58 120 105 50 55 104 32 35 36 37 38 45 10 41 42 43 44 45 71 47 48 49 34 140 52 53 54 115 44 28 58 59 60 61 62 63 64 132 66 67 68 69 70 71 69 24 74 75 76 77 133 79 80 81 82 100 84 31 86 87 88 100 90 91 92 93 94 95 96 97...
output:
1316 158 6401 5280 158 6240 5280 4320 6240 6080 4320 5600 6080 5439 5600 6400 5439 5119 6400 4639 5119 5436 4639 6399 5436 5117 6399 5435 5117 4159 5435 5920 4159 4960 5920 5754 4960 6238 5754 5598 6238 4800 5598 6393 4800 5431 6393 6077 5431 4638 6077 6237 4638 6073 6237 5113 6073 6072 5113 5749 60...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #11:
score: 2
Acceptable Answer
time: 6ms
memory: 7540kb
input:
400 100 88 82 9 2 90 1 83 32 32 79 8 79 63 67 85 82 50 63 69 2 7 91 21 90 69 3 39 78 66 83 96 53 24 65 56 63 90 54 35 55 94 22 76 12 54 55 5 49 91 73 8 19 64 54 39 23 13 27 34 4 81 52 13 11 36 45 3 50 82 81 42 50 75 15 99 70 29 26 70 66 34 15 42 83 16 19 19 12 76 1 68 49 7 17 64 37 98 34 99 37 34 64...
output:
14611 100 40001 40000 100 39499 40000 39899 39499 39700 39899 39398 39700 39998 39398 39897 39998 39796 39897 39896 39796 39997 39896 39697 39997 39894 39697 39198 39894 39795 39198 39996 39795 39696 39996 39598 39696 39793 39598 39892 39793 39596 39892 39498 39596 39693 39498 39890 39693 39300 3989...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #12:
score: 2
Acceptable Answer
time: 2ms
memory: 5204kb
input:
301 20 8 1 1 1 1 1 1 17 1 9 1 5 1 1 1 1 13 1 9 1 18 1 1 16 1 15 5 19 1 8 11 10 1 1 1 1 18 4 1 1 1 1 16 1 1 1 12 10 1 1 1 14 11 13 1 1 1 1 1 1 10 1 1 1 1 1 1 19 14 1 1 1 5 1 1 1 1 13 1 18 1 1 4 1 1 1 1 1 1 1 1 1 1 16 16 10 1 14 18 1 1 1 7 1 1 1 1 6 9 1 13 1 1 1 2 1 1 1 1 1 1 10 1 1 1 17 1 10 10 1 12 ...
output:
4260 20 6021 6020 20 5700 6020 6018 5700 5680 6018 5980 5680 5660 5980 5960 5660 5640 5960 5939 5640 6017 5939 5619 6017 5920 5619 5599 5920 5900 5599 5580 5900 5880 5580 5560 5880 5820 5560 5540 5820 5800 5540 5480 5800 5760 5480 5440 5760 5398 5440 6016 5398 5420 6016 5380 5420 6000 5380 5397 6000...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #13:
score: 2
Acceptable Answer
time: 12ms
memory: 10488kb
input:
300 300 215 159 263 206 201 183 286 56 142 10 231 214 34 54 263 250 169 208 239 148 104 22 244 17 74 68 184 52 2 30 42 83 222 106 25 152 37 225 213 213 69 273 91 221 207 48 166 28 221 50 46 64 10 254 207 109 206 144 270 291 195 197 253 235 141 186 102 68 52 24 38 6 181 44 256 200 77 233 285 163 223 ...
output:
32648 299 90001 89699 299 88500 89699 90000 88500 89698 90000 88800 89698 89999 88800 89697 89999 89100 89697 87900 89100 89696 87900 89998 89696 89694 89998 89996 89694 89400 89996 88799 89400 89995 88799 88498 89995 89099 88498 87600 89099 89097 87600 88798 89097 87599 88798 89993 87599 89692 8999...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #14:
score: 2
Acceptable Answer
time: 14ms
memory: 16584kb
input:
201 400 1 1 1 1 1 152 1 1 1 1 1 1 1 33 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 300 154 1 1 147 1 1 1 383 186 1 1 90 256 1 1 1 1 1 1 1 63 1 1 1 1 208 1 1 1 1 31 1 1 1 1 1 1 1 127 1 1 29 216 397 393 1 1 1 1 1 1 279 1 1 1 1 55 1 1 215 249 1 1 1 1 1 1 172 1 1 1 1 1 1 1 1 1 1 1 1 349 1 331 1 1 1 1 1 1 1 34...
output:
63990 400 80401 80000 400 79600 80000 79199 79600 79999 79199 79198 79999 78800 79198 80400 78800 79998 80400 80398 79998 79196 80398 78400 79196 79997 78400 79599 79997 78799 79599 79996 78799 79195 79996 78000 79195 80397 78000 79995 80397 78798 79995 79994 78798 77999 79994 78797 77999 79597 7879...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #15:
score: 2
Acceptable Answer
time: 8ms
memory: 4488kb
input:
400 400 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
217 784 160001 118784 784 160001 118784 3172 160001 115020 3172 45736 115020 13003 45736 62203 13003 52743 62203 112743 52743 148343 112743 98343 148343 95543 98343 49143 95543 12909 49143 132351 12909 94351 132351 119963 94351 152588 119963 138000 152588 139600 138000 137788 139600 34396 137788 103...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #16:
score: 2
Acceptable Answer
time: 4ms
memory: 8652kb
input:
301 200 50 129 146 60 183 51 47 77 26 73 1 45 1 44 149 1 81 196 17 16 163 35 159 71 1 94 161 138 138 27 76 1 102 42 5 186 176 1 111 198 37 63 81 155 95 164 132 135 155 194 126 98 31 34 121 19 175 148 33 105 25 122 91 165 1 69 1 197 12 98 1 155 5 53 42 1 60 98 78 61 155 13 1 171 102 152 95 61 87 200 ...
output:
23506 200 60201 60200 200 59198 60200 59400 59198 59800 59400 60000 59800 59799 60000 58599 59799 59996 58599 59600 59996 59994 59600 59196 59994 59993 59196 59596 59993 59797 59596 59992 59797 59194 59992 59000 59194 59796 59000 59991 59796 58598 59991 59990 58598 59595 59990 60199 59595 59793 6019...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #17:
score: 2
Acceptable Answer
time: 13ms
memory: 19580kb
input:
201 400 1 1 1 1 1 1 1 1 1 1 1 1 1 263 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 246 1 1 1 1 1 1 1 1 1 1 1 1 1 1 107 1 1 1 1 1 1 1 1 57 1 1 1 1 1 1 1 224 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 90 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
output:
77869 400 80401 80400 400 80000 80400 79600 80000 80399 79600 79599 80399 78800 79599 79598 78800 78400 79598 80397 78400 78799 80397 78399 78799 79998 78399 80396 79998 78398 80396 79596 78398 80395 79596 78000 80395 80394 78000 77600 80394 80393 77600 77200 80393 80392 77200 76800 80392 80391 7680...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #18:
score: 2
Acceptable Answer
time: 13ms
memory: 12884kb
input:
400 300 75 26 289 176 131 196 124 8 230 157 247 265 13 2 210 141 17 200 187 83 21 22 118 144 232 26 284 75 48 30 132 32 65 34 72 36 73 286 164 40 41 261 65 270 221 12 139 48 49 143 91 39 17 258 275 56 151 194 282 55 228 266 296 64 22 232 67 142 69 152 10 102 109 45 75 49 283 112 78 283 81 236 169 22...
output:
43105 298 120001 116097 298 120000 116097 114600 120000 119999 114600 119398 119999 119700 119398 119997 119700 118200 119997 119100 118200 119699 119100 118499 119699 119993 118499 118497 119993 119989 118497 119096 119989 118800 119096 119093 118800 119987 119093 119393 119987 119985 119393 119694...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #19:
score: 2
Acceptable Answer
time: 28ms
memory: 27008kb
input:
333 399 1 1 1 1 1 1 1 28 1 1 1 1 1 1 161 1 17 1 1 1 1 262 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 43 1 1 1 1 1 70 1 1 1 142 1 1 1 1 1 1 1 1 1 1 1 1 70 1 1 1 1 1 1 278 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 245 1 1 1 1 1 1 33 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 106 1 1 1 1 268 1 1 1 172 1 1 1 1 1 312 1 286 1 1 1 1 ...
output:
114795 399 132868 132867 399 132468 132867 131670 132468 132865 131670 132069 132865 132864 132069 131669 132864 132467 131669 131271 132467 132862 131271 131270 132862 132466 131270 130872 132466 132861 130872 130871 132861 132464 130871 130473 132464 132463 130473 130073 132463 132858 130073 13007...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #20:
score: 2
Acceptable Answer
time: 13ms
memory: 15520kb
input:
400 400 100 35 353 385 317 228 7 148 113 165 11 306 209 89 21 166 17 2 19 249 27 305 377 22 3 353 38 28 29 96 191 32 33 309 35 308 100 176 152 40 176 42 43 86 45 46 96 48 396 381 218 246 53 54 334 159 243 360 294 60 33 62 185 64 65 66 191 121 351 107 10 343 367 74 75 201 77 247 79 134 304 92 42 126 ...
output:
55816 399 160001 159594 399 158399 159594 159197 158399 158800 159197 160000 158800 159195 160000 159592 159195 159999 159592 159591 159999 158398 159591 159998 158398 158798 159998 157999 158798 158795 157999 159997 158795 158794 159997 156400 158794 158793 156400 159996 158793 158397 159996 156399...
result:
points 0.40 first subtask is correct but plan is wrong.