QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#500720 | #5280. Depot Rearrangement | ship2077 | 100 ✓ | 19ms | 19144kb | C++14 | 1.2kb | 2024-08-01 18:48:57 | 2024-08-01 18:48:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int M=404;
int n,m,tp,stk[M*M];
vector<int>vec[M];
vector<pair<int,int>>adj[M<<1],ans;
int read(){
int x=0;char ch=getchar();
while (!isdigit(ch)) ch=getchar();
while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
return x;
}
void dfs(int x){
while (!adj[x].empty()){
auto [y,z]=adj[x].back();adj[x].pop_back();
dfs(y); if (z) stk[++tp]=z;
}
}
int main(){
n=read();m=read();
for (int i=1;i<=n;i++){
for (int j=1;j<=m;j++) vec[j].clear();
for (int j=1;j<=m;j++) vec[read()].emplace_back((i-1)*m+j);
for (int j=1;j<=m;j++)
if (vec[j].empty())
adj[i].emplace_back(n+j,0);
else for (int k=1;k<vec[j].size();k++)
adj[n+j].emplace_back(i,vec[j][k]);
}
for (int i=1;i<=n;i++)
if (!adj[i].empty()){
tp=0;dfs(i);
reverse(stk+1,stk+tp+1);
ans.emplace_back(n*m+1,stk[1]);
for (int i=1;i<tp;i++)
ans.emplace_back(stk[i],stk[i+1]);
ans.emplace_back(stk[tp],n*m+1);
}
printf("%d\n",ans.size());
for (auto [x,y]:ans) printf("%d %d\n",x,y);
return 0;
}
詳細信息
Pretests
Final Tests
Test #1:
score: 5
Accepted
time: 0ms
memory: 3980kb
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: 3840kb
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 21 20 20 15 15 10 10 19 19 8 8 18 18 4 4 14 14 3 3 7 7 12 12 2 2 21
result:
ok both subtasks are correct!
Test #3:
score: 5
Accepted
time: 0ms
memory: 3984kb
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 101 89 89 27 27 67 67 76 76 66 66 97 97 36 36 50 50 26 26 87 87 55 55 28 28 100 100 58 58 44 44 79 79 16 16 3 3 49 49 95 95 30 30 90 90 56 56 39 39 75 75 18 18 43 43 20 20 38 38 29 29 6 6 101
result:
ok both subtasks are correct!
Test #4:
score: 5
Accepted
time: 0ms
memory: 3892kb
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 1001 819 819 359 359 775 775 670 670 850 850 734 734 713 713 453 453 184 184 814 814 210 210 830 830 175 175 949 949 109 109 1001 1001 747 747 707 707 1001
result:
ok both subtasks are correct!
Test #5:
score: 5
Accepted
time: 1ms
memory: 3784kb
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 20001 16173 16173 10355 10355 18781 18781 10381 10381 17855 17855 18091 18091 18491 18491 14288 14288 3013 3013 19047 19047 6955 6955 16555 16555 6247 6247 19747 19747 4647 4647 12213 12213 1488 1488 10488 10488 18488 18488 14671 14671 10541 10541 16496 16496 17396 17396 14125 14125 18884 18884 ...
result:
ok both subtasks are correct!
Test #6:
score: 5
Accepted
time: 1ms
memory: 4040kb
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 4021 3899 3899 3992 3992 4020 4020 3994 3994 3872 3872 4015 4015 3966 3966 3871 3871 3977 3977 3914 3914 3957 3957 3798 3798 3857 3857 3874 3874 3980 3980 3940 3940 3832 3832 3794 3794 3780 3780 3652 3652 4013 4013 3912 3912 3760 3760 3640 3640 3776 3776 3796 3796 3754 3754 3913 3913 3894 3894 ...
result:
ok both subtasks are correct!
Test #7:
score: 5
Accepted
time: 2ms
memory: 3816kb
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 90001 72662 72662 11820 11820 72720 72720 81662 81662 58544 58544 85710 85710 20910 20910 54956 54956 13556 13556 42644 42644 44971 44971 53371 53371 26373 26373 19174 19174 85356 85356 31656 31656 9149 9149 73649 73649 26374 26374 16773 16773 30110 30110 16610 16610 17623 17623 80623 80623 7493...
result:
ok both subtasks are correct!
Test #8:
score: 5
Accepted
time: 3ms
memory: 5444kb
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 12041 12040 12040 11739 11739 11438 11438 12039 12039 11437 11437 11137 11137 12038 12038 11136 11136 11738 11738 11135 11135 10836 10836 12037 12037 10835 10835 11737 11737 10834 10834 11436 11436 10833 10833 10535 10535 12036 12036 10534 10534 11736 11736 10234 10234 12035 12035 10233 10233 ...
result:
ok both subtasks are correct!
Test #9:
score: 5
Accepted
time: 4ms
memory: 5800kb
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 40001 39699 39699 39983 39983 39631 39631 39775 39775 39674 39674 39278 39278 39626 39626 39249 39249 39867 39867 39648 39648 39574 39574 37985 37985 39958 39958 39659 39659 39555 39555 39952 39952 39588 39588 39173 39173 39476 39476 39835 39835 39986 39986 39569 39569 38765 38765 38999 38999 ...
result:
ok both subtasks are correct!
Test #10:
score: 5
Accepted
time: 0ms
memory: 4020kb
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 6401 6238 6238 6400 6400 5465 5465 6080 6080 5749 5749 6072 6072 5907 5907 4636 4636 5439 5439 6077 6077 6317 6317 6225 6225 5754 5754 6070 6070 5101 5101 5920 5920 4319 4319 5280 5280 4478 4478 6393 6393 5744 5744 5271 5271 3836 3836 5435 5435 3516 3516 6073 6073 6378 6378 5894 5894 6391 6391 ...
result:
ok both subtasks are correct!
Test #11:
score: 5
Accepted
time: 4ms
memory: 5840kb
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 40001 39795 39795 39566 39566 39467 39467 39390 39390 39266 39266 38947 38947 38763 38763 39936 39936 38484 38484 38920 38920 38570 38570 38296 38296 38692 38692 38798 38798 39462 39462 39368 39368 39995 39995 38469 38469 38588 38588 39899 39899 38168 38168 38256 38256 38418 38418 39873 39873 ...
result:
ok both subtasks are correct!
Test #12:
score: 5
Accepted
time: 1ms
memory: 4384kb
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 6021 6020 6020 5996 5996 5617 5617 6018 6018 5417 5417 6017 6017 5200 5200 6016 6016 4987 4987 6015 6015 5572 5572 6014 6014 5976 5976 5719 5719 5416 5416 4815 4815 6013 6013 5668 5668 6012 6012 5939 5939 5718 5718 5300 5300 6011 6011 4912 4912 6010 6010 4779 4779 6009 6009 5180 5180 6008 6008 ...
result:
ok both subtasks are correct!
Test #13:
score: 5
Accepted
time: 4ms
memory: 7928kb
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 90001 89986 89986 87550 87550 89694 89694 87217 87217 89593 89593 89998 89998 89370 89370 88478 88478 87112 87112 89365 89365 89080 89080 89364 89364 88089 88089 88455 88455 87894 87894 86762 86762 87418 87418 89912 89912 87799 87799 89398 89398 85493 85493 83183 83183 88198 88198 87595 87595 ...
result:
ok both subtasks are correct!
Test #14:
score: 5
Accepted
time: 12ms
memory: 12240kb
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 80401 80400 80400 79998 79998 80398 80398 79596 79596 80199 80199 79194 79194 80393 80393 78992 78992 80197 80197 78792 78792 80392 80392 78390 78390 80391 80391 78187 78187 80196 80196 77985 77985 80390 80390 77787 77787 80195 80195 79145 79145 79997 79997 79595 79595 79996 79996 80356 80356 ...
result:
ok both subtasks are correct!
Test #15:
score: 5
Accepted
time: 2ms
memory: 3748kb
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 160001 118784 118784 784 784 160001 160001 147572 147572 133420 133420 87336 87336 132109 132109 148555 148555 134930 134930 126916 126916 143716 143716 110130 110130 119755 119755 53963 53963 117163 117163 139563 139563 114769 114769 139569 139569 138000 138000 139600 139600 149561 149561 13956...
result:
ok both subtasks are correct!
Test #16:
score: 5
Accepted
time: 6ms
memory: 6856kb
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 60201 60173 60173 59929 59929 60114 60114 59940 59940 59790 59790 60185 60185 58891 58891 60143 60143 57973 57973 59889 59889 60107 60107 58726 58726 60125 60125 58161 58161 60000 60000 57783 57783 60150 60150 59984 59984 58349 58349 60088 60088 59988 59988 59357 59357 60076 60076 58295 58295 ...
result:
ok both subtasks are correct!
Test #17:
score: 5
Accepted
time: 7ms
memory: 13812kb
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 80401 80400 80400 79998 79998 80399 80399 79797 79797 79596 79596 80397 80397 79595 79595 80199 80199 79394 79394 79997 79997 79393 79393 79193 79193 80198 80198 79192 79192 79996 79996 79191 79191 79594 79594 78993 78993 78792 78792 80396 80396 78791 78791 80196 80196 78591 78591 79995 79995 ...
result:
ok both subtasks are correct!
Test #18:
score: 5
Accepted
time: 7ms
memory: 9312kb
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 120001 119982 119982 118794 118794 119654 119654 117811 117811 118795 118795 118940 118940 119525 119525 119883 119883 119692 119692 119296 119296 117594 117594 118192 118192 118345 118345 119699 119699 118488 118488 118863 118863 119960 119960 119069 119069 118739 118739 119956 119956 118657 ...
result:
ok both subtasks are correct!
Test #19:
score: 5
Accepted
time: 19ms
memory: 19144kb
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 132868 132867 132867 132201 132201 132865 132865 131867 131867 132864 132864 131535 131535 132862 132862 131202 131202 132861 132861 130869 130869 132858 132858 130203 130203 132534 132534 129870 129870 132857 132857 129537 129537 132856 132856 129204 129204 132854 132854 129882 129882 132533...
result:
ok both subtasks are correct!
Test #20:
score: 5
Accepted
time: 14ms
memory: 11196kb
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 160001 157793 157793 153428 153428 159158 159158 160000 160000 156577 156577 149599 149599 159195 159195 159991 159991 159039 159039 155589 155589 159024 159024 154932 154932 154800 154800 158798 158798 153200 153200 149478 149478 159594 159594 159113 159113 157984 157984 157198 157198 147979 ...
result:
ok both subtasks are correct!