QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#137058 | #5280. Depot Rearrangement | blackyuki# | 100 ✓ | 56ms | 24948kb | C++14 | 1.7kb | 2023-08-09 18:39:13 | 2024-07-04 01:27:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP(i,k,n) for(ll i=(ll)(k);i<(ll)(n);i++)
#define pb emplace_back
#define fi first
#define se second
#define all(a) a.begin(),a.end()
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
const ll inf=1001001001001001001;
int main(){
ll n,m;cin>>n>>m;
vvi v(n,vi(m));
rep(i,n)rep(j,m){
cin>>v[i][j];v[i][j]--;
}
vvvi al(n,vvi(m));
rep(i,n)rep(j,m)al[i][v[i][j]].pb(i*m+j);
vvp g(n+m);
rep(i,n)rep(j,m){
if(al[i][j].size()==0){
g[i].pb(j+n,-1);
}
else{
while(al[i][j].size()>1){
g[j+n].pb(i,al[i][j].back());
al[i][j].pop_back();
}
}
}
vi edge;
auto dfs=[&](auto && self, ll i) -> void {
while(g[i].size()){
P x=g[i].back();g[i].pop_back();
self(self,x.fi);
if(x.se!=-1)edge.pb(x.se);
}
};
vp ans;
rep(j,m)if(g[j+n].size()){
edge=vi(0);
dfs(dfs,j+n);
reverse(all(edge));
ll cur=n*m;
for(ll x:edge){
ans.pb(x,cur);
cur=x;
}
ans.pb(n*m,cur);
}
out(ans.size());
for(auto x:ans)cout<<x.fi+1<<' '<<x.se+1<<endl;
}
详细
Test #1:
score: 5
Accepted
time: 0ms
memory: 3516kb
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: 3520kb
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 2 21 18 2 14 18 10 14 19 10 7 19 20 7 3 20 15 3 4 15 8 4 12 8 21 12
result:
ok both subtasks are correct!
Test #3:
score: 5
Accepted
time: 0ms
memory: 3608kb
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 97 101 89 97 26 89 67 26 75 67 66 75 56 66 36 56 44 36 27 44 87 27 55 87 50 55 79 50 16 79 3 16 28 3 95 28 58 95 39 58 76 39 49 76 100 49 30 100 90 30 29 90 20 29 43 20 6 43 18 6 38 18 101 38
result:
ok both subtasks are correct!
Test #4:
score: 5
Accepted
time: 1ms
memory: 3884kb
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 819 1001 359 819 949 359 109 949 453 109 184 453 814 184 775 814 670 775 830 670 175 830 210 175 850 210 734 850 713 734 1001 713 747 1001 707 747 1001 707
result:
ok both subtasks are correct!
Test #5:
score: 5
Accepted
time: 4ms
memory: 4876kb
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 19529 20001 18829 19529 15999 18829 19184 15999 19298 19184 16885 19298 16173 16885 10355 16173 18781 10355 10381 18781 17855 10381 18091 17855 18491 18091 14288 18491 3013 14288 19047 3013 6955 19047 16555 6955 6247 16555 19747 6247 4647 19747 12213 4647 1488 12213 10488 1488 18488 10488 14671 ...
result:
ok both subtasks are correct!
Test #6:
score: 5
Accepted
time: 0ms
memory: 3984kb
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 3930 4021 3871 3930 4015 3871 3994 4015 4020 3994 3992 4020 3872 3992 3977 3872 3857 3977 3899 3857 3966 3899 3913 3966 3957 3913 3794 3957 3832 3794 3798 3832 3776 3798 3652 3776 4013 3652 3912 4013 3754 3912 3640 3754 3780 3640 3874 3780 3980 3874 3940 3980 3914 3940 3890 3914 3932 3890 3758 ...
result:
ok both subtasks are correct!
Test #7:
score: 5
Accepted
time: 6ms
memory: 9440kb
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 73649 90001 85356 73649 31656 85356 26374 31656 16773 26374 27271 16773 61771 27271 58544 61771 85710 58544 20910 85710 54956 20910 13556 54956 42644 13556 57662 42644 82270 57662 57670 82270 1262 57670 72662 1262 11820 72662 72720 11820 75733 72720 37143 75733 87877 37143 84877 87877 35684 8487...
result:
ok both subtasks are correct!
Test #8:
score: 5
Accepted
time: 8ms
memory: 5864kb
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 282 12041 12002 282 11722 12002 11402 11722 12003 11402 11403 12003 11122 11403 12004 11122 11123 12004 11723 11123 11124 11723 10802 11124 12005 10802 10803 12005 11724 10803 10804 11724 11404 10804 10805 11404 10522 10805 12006 10522 10523 12006 11725 10523 10202 11725 12007 10202 10203 1200...
result:
ok both subtasks are correct!
Test #9:
score: 5
Accepted
time: 14ms
memory: 7660kb
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 39765 40001 39659 39765 39934 39659 39626 39934 39775 39626 39835 39775 39648 39835 39278 39648 39631 39278 39249 39631 39867 39249 39954 39867 39674 39954 39574 39674 39699 39574 39555 39699 39952 39555 39588 39952 39173 39588 39476 39173 38765 39476 38999 38765 37985 38999 39958 37985 39569 ...
result:
ok both subtasks are correct!
Test #10:
score: 5
Accepted
time: 3ms
memory: 4164kb
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 6047 6401 5749 6047 6072 5749 5907 6072 4636 5907 5465 4636 6400 5465 5435 6400 6077 5435 6317 6077 6225 6317 6080 6225 5101 6080 5920 5101 4319 5920 5280 4319 6238 5280 5754 6238 6070 5754 6378 6070 5744 6378 5271 5744 3836 5271 5439 3836 3516 5439 6393 3516 5853 6393 6391 5853 6204 6391 5270 ...
result:
ok both subtasks are correct!
Test #11:
score: 5
Accepted
time: 7ms
memory: 7908kb
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 39755 40001 39566 39755 39467 39566 39795 39467 39873 39795 39390 39873 39266 39390 38920 39266 38763 38920 39936 38763 38484 39936 38947 38484 38570 38947 38296 38570 38692 38296 38798 38692 39462 38798 39368 39462 39995 39368 38415 39995 38588 38415 39814 38588 39956 39814 39334 39956 39992 ...
result:
ok both subtasks are correct!
Test #12:
score: 5
Accepted
time: 0ms
memory: 4468kb
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 5932 6021 5996 5932 5617 5996 6002 5617 5704 6002 5403 5704 6003 5403 5406 6003 4803 5406 6007 4803 5199 6007 6008 5199 4987 6008 6009 4987 5572 6009 6010 5572 5966 6010 5705 5966 5300 5705 6011 5300 5668 6011 6012 5668 5939 6012 5408 5939 4883 5408 5706 4883 5200 5706 5102 5200 6013 5102 4912 ...
result:
ok both subtasks are correct!
Test #13:
score: 5
Accepted
time: 16ms
memory: 12080kb
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 89586 90001 87550 89586 89694 87550 89998 89694 87112 89998 89986 87112 89254 89986 89593 89254 89370 89593 89080 89370 89364 89080 88089 89364 88455 88089 87217 88455 89365 87217 87799 89365 86762 87799 88478 86762 87894 88478 89398 87894 89088 89398 86694 89088 83183 86694 88198 83183 87401 ...
result:
ok both subtasks are correct!
Test #14:
score: 5
Accepted
time: 24ms
memory: 15496kb
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 58310 80401 80202 58310 79799 80202 80203 79799 79398 80203 80002 79398 78994 80002 80204 78994 78802 80204 80003 78802 78593 80003 80205 78593 78191 80205 80206 78191 78002 80206 80004 78002 77789 80004 80208 77789 77603 80208 80005 77603 79145 80005 79800 79145 79399 79800 79801 79399 80356 ...
result:
ok both subtasks are correct!
Test #15:
score: 5
Accepted
time: 15ms
memory: 13644kb
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 158790 160001 25190 158790 88665 25190 62569 88665 115932 62569 83888 115932 83273 83888 90073 83273 8955 90073 148555 8955 134930 148555 126916 134930 143716 126916 110130 143716 119755 110130 53963 119755 117163 53963 139563 117163 114769 139563 139569 114769 138000 139569 139600 138000 149561...
result:
ok both subtasks are correct!
Test #16:
score: 5
Accepted
time: 20ms
memory: 9752kb
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 58389 60201 60023 58389 59889 60023 60114 59889 59940 60114 59634 59940 60030 59634 58891 60030 60039 58891 57958 60039 59929 57958 60107 59929 58691 60107 60125 58691 58161 60125 60000 58161 57769 60000 60150 57769 59908 60150 58295 59908 59834 58295 59357 59834 60065 59357 59988 60065 57458 ...
result:
ok both subtasks are correct!
Test #17:
score: 5
Accepted
time: 31ms
memory: 17056kb
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 2 80401 80201 2 79799 80201 80202 79799 79602 80202 79397 79602 80203 79397 79398 80203 80002 79398 79202 80002 79800 79202 79203 79800 78995 79203 80003 78995 78996 80003 79801 78996 78997 79801 79399 78997 78802 79399 78593 78802 80205 78593 78594 80205 80004 78594 78402 80004 79802 78402 78...
result:
ok both subtasks are correct!
Test #18:
score: 5
Accepted
time: 42ms
memory: 15676kb
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 119581 120001 118794 119581 119982 118794 117811 119982 118795 117811 118863 118795 119525 118863 119883 119525 119692 119883 119189 119692 117430 119189 118192 117430 119654 118192 118488 119654 119586 118488 118739 119586 119956 118739 119069 119956 119960 119069 118657 119960 119091 118657 ...
result:
ok both subtasks are correct!
Test #19:
score: 5
Accepted
time: 52ms
memory: 24948kb
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 23021 132868 132536 23021 132072 132536 132538 132072 131672 132538 132539 131672 131273 132539 132540 131273 130875 132540 132541 130875 130538 132541 132542 130538 130076 132542 132470 130076 129677 132470 132544 129677 129278 132544 132545 129278 128879 132545 132546 128879 129877 132546 1...
result:
ok both subtasks are correct!
Test #20:
score: 5
Accepted
time: 56ms
memory: 20000kb
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 158345 160001 159997 158345 157793 159997 153428 157793 159024 153428 160000 159024 159039 160000 159991 159039 157599 159991 159550 157599 159113 159550 155579 159113 159158 155579 154932 159158 156577 154932 149478 156577 159195 149478 157984 159195 158798 157984 154800 158798 157191 154800 ...
result:
ok both subtasks are correct!