QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#142687 | #5280. Depot Rearrangement | penguinman | 35 | 203ms | 37148kb | C++17 | 2.7kb | 2023-08-19 17:56:41 | 2023-08-19 17:56:44 |
Judging History
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
int main(){
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll N,M; cin >> N >> M;
vector<vii> data(N,vii(M));
vi A(N*M);
rep(i,0,N*M){
cin >> A[i];
A[i]--;
data[i/M][A[i]].pb(i);
}
vii edge(N+M), weight(N+M);
{
ll cnt = N*M;
rep(i,0,N){
rep(j,0,M){
if(data[i][j].size() == 0){
edge[j].pb(M+i);
weight[j].pb(cnt++);
}
else{
rep(k,1,data[i][j].size()){
edge[M+i].pb(j);
weight[M+i].pb(data[i][j][k]);
}
}
}
}
}
ll ans = 0;
{
vector<bool> flag(N+M);
rep(i,0,N+M){
if(edge[i].empty()) continue;
if(flag[i]) continue;
flag[i] = true;
std::queue<ll> que;
que.push(i);
ll sum = 0;
while(!que.empty()){
ll now = que.front();
que.pop();
sum += edge[now].size();
for(auto next: edge[now]){
if(flag[next]) continue;
flag[next] = true;
que.push(next);
}
}
sum /= 2;
ans += sum+1;
}
cout << ans << ln;
}
vector<bool> used(N*M*2);
vi ord;
std::function<void(ll)> dfs = [&](ll now){
rep(i,0,edge[now].size()){
ll next = edge[now][i];
ll idx = weight[now][i];
if(used[idx]) continue;
used[idx] = true;
dfs(next);
ord.pb(idx);
}
};
rep(i,0,N+M){
dfs(i);
{
vi nord;
for(auto el: ord){
if(el < N*M) nord.pb(el);
}
ord = nord;
}
if(ord.empty()) continue;
reverse(all(ord));
cout << ord[0]+1 << " " << N*M+1 << ln;
rep(j,1,ord.size()) cout << ord[j]+1 << " "<< ord[j-1]+1 << ln;
cout << N+M+1 << " " << ord.back()+1 << ln;
ord.clear();
}
}
詳細信息
Test #1:
score: 5
Accepted
time: 0ms
memory: 3488kb
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: 2
Acceptable Answer
time: 1ms
memory: 3468kb
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 10 21 2 10 14 2 3 14 18 3 7 18 15 7 8 15 19 8 12 19 20 12 4 20 10 4
result:
points 0.40 first subtask is correct but plan is wrong.
Test #3:
score: 2
Acceptable Answer
time: 1ms
memory: 3540kb
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 38 101 18 38 6 18 29 6 67 29 30 67 75 30 39 75 49 39 90 49 28 90 3 28 20 3 43 20 16 43 36 16 56 36 87 56 26 87 44 26 55 44 95 55 27 95 89 27 76 89 66 76 100 66 50 100 79 50 58 79 97 58 21 97
result:
points 0.40 first subtask is correct but plan is wrong.
Test #4:
score: 0
Wrong Answer
time: 1ms
memory: 3544kb
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 819 109 713 819 734 713 850 734 210 850 175 210 830 175 670 830 775 670 359 775 949 359 814 949 184 814 453 184 111 453 707 1001 747 707 111 747
result:
wrong output format Extra information in the output file
Test #5:
score: 0
Wrong Answer
time: 3ms
memory: 4632kb
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 2067 20001 6867 2067 13167 6867 7667 13167 5967 7667 16367 5967 8254 16367 10354 8254 7854 10354 16854 7854 16619 16854 14671 16619 3641 14671 4955 3641 12213 4955 3013 12213 12259 3013 459 12259 17871 459 3971 17871 17855 3971 1862 17855 5159 1862 1488 5159 14250 1488 9050 14250 14288 9050 1459...
result:
wrong output format Extra information in the output file
Test #6:
score: 2
Acceptable Answer
time: 2ms
memory: 4120kb
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 37 4021 53 37 84 53 4 84 29 4 80 29 93 80 258 93 104 258 211 104 169 211 60 169 18 60 34 18 358 34 140 358 12 140 40 12 11 40 171 11 98 171 416 98 107 416 331 107 144 331 178 144 28 178 55 28 499 55 88 499 380 88 180 380 155 180 187 155 70 187 193 70 129 193 210 129 78 210 100 78 194 100 217 19...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #7:
score: 0
Wrong Answer
time: 10ms
memory: 8844kb
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 9149 90001 19174 9149 26374 19174 31656 26374 85384 31656 73384 85384 51840 73384 25140 51840 70046 25140 22576 70046 15076 22576 38476 15076 36376 38476 77677 36376 8377 77677 34894 8377 39694 34894 34177 39694 27413 34177 8603 27413 28103 8603 74498 28103 31298 74498 89003 31298 14346 89003 83...
result:
wrong output format Extra information in the output file
Test #8:
score: 2
Acceptable Answer
time: 12ms
memory: 6760kb
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 322 12041 2 322 362 2 42 362 402 42 82 402 442 82 122 442 482 122 162 482 522 162 202 522 562 202 242 562 602 242 642 602 3 642 643 3 43 643 682 43 83 682 722 83 123 722 762 123 163 762 802 163 203 802 842 203 243 842 882 243 282 882 922 282 4 922 962 4 44 962 1002 44 84 1002 1042 84 124 1042 ...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #9:
score: 2
Acceptable Answer
time: 16ms
memory: 8936kb
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 196 40001 96 196 172 96 242 172 163 242 337 163 489 337 57 489 249 57 743 249 1181 743 1099 1181 1356 1099 345 1356 1644 345 97 1644 480 97 600 480 482 600 99 482 139 99 571 139 1571 571 381 1571 2166 381 1771 2166 639 1771 1998 639 761 1998 2266 761 437 2266 900 437 560 900 496 560 67 496 429...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #10:
score: 2
Acceptable Answer
time: 1ms
memory: 4224kb
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 137 6401 338 137 40 338 182 40 806 182 977 806 2009 977 1034 2009 839 1034 234 839 353 234 17 353 2105 17 1428 2105 1119 1428 750 1119 510 750 3288 510 534 3288 1581 534 2337 1581 276 2337 757 276 73 757 281 73 938 281 1025 938 396 1025 192 396 155 192 2417 155 3453 2417 245 3453 1366 245 861 1...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #11:
score: 2
Acceptable Answer
time: 13ms
memory: 8868kb
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 794 40001 170 794 982 170 483 982 550 483 1183 550 159 1183 397 159 186 397 253 186 1362 253 495 1362 90 495 1825 90 293 1825 353 293 558 353 1970 558 1097 1970 577 1097 1618 577 866 1618 2041 866 1860 2041 298 1860 592 298 374 592 892 374 2159 892 300 2159 393 300 1265 393 2113 1265 243 2113 ...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #12:
score: 2
Acceptable Answer
time: 5ms
memory: 4824kb
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 322 6021 3 322 343 3 23 343 362 23 42 362 383 42 63 383 402 63 82 402 423 82 123 423 445 123 143 445 482 143 162 482 502 162 203 502 524 203 242 524 544 242 262 544 602 262 283 602 622 283 4 622 642 4 25 642 665 25 44 665 723 44 64 723 742 64 84 742 763 84 102 763 784 102 124 784 802 124 144 80...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #13:
score: 2
Acceptable Answer
time: 18ms
memory: 15440kb
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 597 90001 1710 597 212 1710 712 212 1962 712 861 1962 2525 861 3254 2525 1590 3254 231 1590 3211 231 1896 3211 53 1896 974 53 5432 974 1014 5432 6099 1014 2491 6099 1458 2491 7588 1458 100 7588 1651 100 660 1651 487 660 1243 487 218 1243 3504 218 9554 3504 3228 9554 2183 3228 296 2183 667 296 ...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #14:
score: 2
Acceptable Answer
time: 95ms
memory: 22568kb
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 404 80401 2 404 802 2 3 802 1203 3 1602 1203 4 1602 1603 4 405 1603 803 405 1204 803 2002 1204 5 2002 2003 5 406 2003 1205 406 2402 1205 7 2402 2404 7 408 2404 1604 408 804 1604 1605 804 2004 1605 1197 2004 2005 1197 1206 2005 3202 1206 8 3202 2802 8 809 2802 9 809 3203 9 409 3203 2006 409 240...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #15:
score: 0
Wrong Answer
time: 13ms
memory: 13396kb
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 78790 160001 138790 78790 25053 138790 8955 25053 90073 8955 83273 90073 83888 83273 48288 83888 90155 48288 9053 90155 25057 9053 75857 25057 16140 75857 20798 16140 4989 20798 24189 4989 128398 24189 20540 128398 16377 20540 113977 16377 16191 113977 36721 16191 126703 36721 47903 126703 29909...
result:
wrong output format Extra information in the output file
Test #16:
score: 2
Acceptable Answer
time: 17ms
memory: 12008kb
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 621 60201 220 621 1234 220 232 1234 2980 232 13 2980 3392 13 1253 3392 563 1253 4989 563 633 4989 419 633 1659 419 1307 1659 1934 1307 2334 1934 1827 2334 16 1827 5357 16 2164 5357 6254 2164 458 6254 2600 458 25 2600 6412 25 2914 6412 467 2914 2798 467 6916 2798 246 6916 7184 246 3027 7184 507...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #17:
score: 2
Acceptable Answer
time: 119ms
memory: 25072kb
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 802 80401 2 802 1202 2 3 1202 1604 3 4 1604 2002 4 5 2002 2402 5 6 2402 2802 6 7 2802 3202 7 8 3202 3602 8 9 3602 4002 9 10 4002 4402 10 11 4402 4802 11 12 4802 5202 12 13 5202 5981 13 402 5981 803 402 1203 803 404 1203 804 404 1605 804 915 1605 2003 915 405 2003 1204 405 1606 1204 2004 1606 8...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #18:
score: 2
Acceptable Answer
time: 50ms
memory: 20108kb
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 124 120001 392 124 253 392 427 253 1692 427 690 1692 1496 690 3291 1496 421 3291 775 421 243 775 4136 243 1404 4136 4679 1404 600 4679 745 600 4124 745 1216 4124 1656 1216 806 1656 4607 806 2642 4607 372 2642 1436 372 5160 1436 2215 5160 5553 2215 3713 5553 5682 3713 4322 5682 8290 4322 2370 8...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #19:
score: 2
Acceptable Answer
time: 203ms
memory: 37148kb
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 401 132868 800 401 1199 800 2 1199 1200 2 404 1200 1201 404 1598 1201 3 1598 1599 3 405 1599 1600 405 801 1600 1601 801 1997 1601 4 1997 1998 4 406 1998 2386 406 802 2386 2000 802 5 2000 2397 5 6 2397 3046 6 1202 3046 2001 1202 407 2001 2398 407 408 2398 2796 408 7 2796 3194 7 9 3194 3593 9 1...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #20:
score: 2
Acceptable Answer
time: 55ms
memory: 25672kb
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 147 160001 523 147 1228 523 569 1228 2388 569 546 2388 391 546 1984 391 4380 1984 2332 4380 1901 2332 1540 1901 1074 1540 5423 1074 2632 5423 11280 2632 2953 11280 11751 2953 1162 11751 3820 1162 13326 3820 4724 13326 14091 4724 1914 14091 920 1914 690 920 2064 690 2968 2064 287 2968 4960 287 ...
result:
points 0.40 first subtask is correct but plan is wrong.