QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117344 | #5280. Depot Rearrangement | AFewSuns | 70 | 16ms | 10904kb | C++14 | 2.1kb | 2023-07-01 00:03:30 | 2023-07-01 00:03:34 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
namespace my_std{
#define ll long long
#define bl bool
ll my_pow(ll a,ll b,ll mod){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res=(res*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return res;
}
ll qpow(ll a,ll b){
ll res=1;
if(!b) return 1;
while(b){
if(b&1) res*=a;
a*=a;
b>>=1;
}
return res;
}
#define db double
#define pf printf
#define pc putchar
#define fr(i,x,y) for(register ll i=(x);i<=(y);i++)
#define pfr(i,x,y) for(register ll i=(x);i>=(y);i--)
#define go(u) for(ll i=head[u];i;i=e[i].nxt)
#define enter pc('\n')
#define space pc(' ')
#define fir first
#define sec second
#define MP make_pair
#define il inline
#define inf 8e18
#define random(x) rand()*rand()%(x)
#define inv(a,mod) my_pow((a),(mod-2),(mod))
il ll read(){
ll sum=0,f=1;
char ch=0;
while(!isdigit(ch)){
if(ch=='-') f=-1;
ch=getchar();
}
while(isdigit(ch)){
sum=sum*10+(ch^48);
ch=getchar();
}
return sum*f;
}
il void write(ll x){
if(x<0){
x=-x;
pc('-');
}
if(x>9) write(x/10);
pc(x%10+'0');
}
il void writeln(ll x){
write(x);
enter;
}
il void writesp(ll x){
write(x);
space;
}
}
using namespace my_std;
vector<ll> ans;
ll n,m,a[440],head[880],cnt=0;
bl ck[440];
struct node{
ll nxt,to,w;
}e[200020];
void add(ll u,ll v,ll ww){
e[++cnt].nxt=head[u];
e[cnt].to=v;
e[cnt].w=ww;
head[u]=cnt;
}
void dfs(ll u){
for(ll i=head[u];i;i=head[u]){
head[u]=e[i].nxt;
ll v=e[i].to;
dfs(v);
if(e[i].w) ans.push_back(e[i].w);
}
}
int main(){
n=read();
m=read();
fr(i,1,n){
ll tmp=cnt;
fr(j,1,m){
a[j]=read();
if(ck[a[j]]) add(i,n+a[j],(i-1)*m+j);
ck[a[j]]=1;
}
fr(j,1,m){
if(!ck[j]) add(n+j,i,0);
ck[j]=0;
}
if((tmp-cnt)>m) writeln(tmp-cnt);
if(cnt>m*i) writeln(cnt);
}
if(cnt>n*m) writeln(cnt);
ans.push_back(n*m+1);
fr(i,1,n){
if(head[i]){
dfs(i);
ans.push_back(n*m+1);
}
}
writeln((ll)ans.size()-1);
fr(i,1,(ll)ans.size()-1) pf("%lld %lld\n",ans[i],ans[i-1]);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 1ms
memory: 3340kb
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: 0
Wrong Answer
time: 1ms
memory: 3592kb
input:
5 4 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4
output:
6 10 14 18 24 24 13 10 21 2 10 14 2 7 14 15 7 3 15 18 3 8 18 19 8 12 19 20 12 4 20 21 4
result:
wrong answer first subtask is incorrect
Test #3:
score: 5
Accepted
time: 0ms
memory: 3764kb
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 18 101 26 18 16 26 43 16 27 43 87 27 3 87 28 3 75 28 55 75 36 55 20 36 38 20 44 38 76 44 89 76 49 89 39 49 29 39 95 29 66 95 97 66 30 97 90 30 56 90 50 56 100 50 58 100 79 58 67 79 6 67 101 6
result:
ok both subtasks are correct!
Test #4:
score: 5
Accepted
time: 1ms
memory: 3536kb
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 453 1001 184 453 814 184 359 814 775 359 175 775 210 175 830 210 670 830 850 670 734 850 713 734 819 713 949 819 109 949 1001 109 747 1001 707 747 1001 707
result:
ok both subtasks are correct!
Test #5:
score: 5
Accepted
time: 1ms
memory: 3832kb
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 13073 20001 12213 13073 10354 12213 7854 10354 459 7854 3259 459 1459 3259 5159 1459 1862 5159 3158 1862 1858 3158 3192 1858 1892 3192 7562 1892 8849 7562 475 8849 1541 475 17469 1541 1569 17469 4941 1569 16555 4941 6955 16555 17855 6955 4955 17855 15140 4955 11540 15140 10355 11540 11555 10355 ...
result:
ok both subtasks are correct!
Test #6:
score: 5
Accepted
time: 1ms
memory: 3724kb
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 47 4021 28 47 64 28 29 64 4 29 84 4 33 84 164 33 88 164 51 88 344 51 34 344 168 34 36 168 92 36 53 92 206 53 104 206 70 104 37 70 231 37 11 231 262 11 74 262 126 74 106 126 76 106 210 76 245 210 38 245 303 38 290 303 252 290 93 252 144 93 384 144 369 384 306 369 446 306 326 446 107 326 525 107 ...
result:
ok both subtasks are correct!
Test #7:
score: 5
Accepted
time: 3ms
memory: 3544kb
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 72662 90001 11820 72662 72720 11820 75733 72720 37143 75733 68130 37143 22642 68130 36376 22642 38476 36376 39588 38476 77388 39588 69294 77388 1916 69294 55164 1916 13556 55164 85710 13556 20910 85710 42644 20910 44971 42644 53371 44971 26373 53371 19174 26373 85356 19174 31656 85356 76686 3165...
result:
ok both subtasks are correct!
Test #8:
score: 0
Wrong Answer
time: 3ms
memory: 4916kb
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:
78 156 234 312 390 468 542 618 696 774 852 930 1008 1086 1164 1240 1318 1394 1472 1550 1628 1704 1778 1854 1932 2010 2088 2166 2244 2322 2396 2474 2552 2630 2708 2786 2864 2940 3018 3094 3172 3250 3328 3406 3484 3560 3638 3716 3792 3870 3946 4022 4098 4176 4254 4328 4404 4480 4558 4636 4712 4790 486...
result:
wrong answer first subtask is incorrect
Test #9:
score: 5
Accepted
time: 4ms
memory: 5176kb
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 512 40001 113 512 7 113 206 7 22 206 210 22 118 210 319 118 24 319 1005 24 215 1005 713 215 31 713 125 31 418 125 613 418 218 613 128 218 715 128 32 715 513 32 329 513 129 329 33 129 917 33 130 917 34 130 133 34 219 133 40 219 520 40 230 520 136 230 330 136 720 330 627 720 138 627 920 138 239 ...
result:
ok both subtasks are correct!
Test #10:
score: 5
Accepted
time: 1ms
memory: 3716kb
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 338 6401 1936 338 977 1936 806 977 182 806 1328 182 2105 1328 17 2105 831 17 666 831 189 666 504 189 1174 504 28 1174 192 28 40 192 353 40 1470 353 45 1470 2417 45 195 2417 839 195 705 839 52 705 1178 52 714 1178 56 714 366 56 1803 366 205 1803 1340 205 226 1340 841 226 229 841 1631 229 58 1631...
result:
ok both subtasks are correct!
Test #11:
score: 5
Accepted
time: 2ms
memory: 6980kb
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 119 40001 1115 119 9 1115 132 9 12 132 311 12 16 311 207 16 18 207 134 18 20 134 507 20 317 507 24 317 820 24 138 820 329 138 709 329 140 709 25 140 331 25 30 331 603 30 419 603 36 419 141 36 339 141 1314 339 727 1314 430 727 37 430 905 37 340 905 45 340 1421 45 341 1421 208 341 347 208 147 34...
result:
ok both subtasks are correct!
Test #12:
score: 0
Wrong Answer
time: 2ms
memory: 4004kb
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:
28 48 74 100 128 156 182 208 238 262 288 318 350 380 410 436 460 492 526 556 586 620 644 670 700 724 752 778 810 838 866 898 926 948 978 1004 1036 1066 1090 1122 1148 1174 1202 1234 1262 1290 1322 1346 1372 1402 1430 1466 1496 1526 1556 1582 1612 1638 1668 1698 1724 1756 1790 1816 1848 1876 1908 193...
result:
wrong answer first subtask is incorrect
Test #13:
score: 5
Accepted
time: 7ms
memory: 6728kb
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 631 90001 15 631 309 15 1213 309 312 1213 40 312 916 40 49 916 945 49 1813 945 962 1813 53 962 332 53 55 332 2726 55 637 2726 335 637 644 335 350 644 648 350 2730 648 354 2730 660 354 360 660 1521 360 1816 1521 361 1816 57 361 966 57 68 966 363 68 2148 363 1217 2148 970 1217 366 970 69 366 123...
result:
ok both subtasks are correct!
Test #14:
score: 0
Wrong Answer
time: 10ms
memory: 10144kb
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:
644 1290 1930 2554 3194 3808 4422 5060 5686 6346 6962 7596 8238 8884 9544 10150 10768 11382 12020 12648 13290 13918 14576 15210 15838 16466 17134 17746 18384 19020 19658 20288 20906 21528 22168 22800 23404 24078 24694 25332 25964 26594 27250 27902 28558 29180 29836 30474 31130 31760 32398 33016 3364...
result:
wrong answer first subtask is incorrect
Test #15:
score: 5
Accepted
time: 4ms
memory: 3600kb
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 118784 160001 784 118784 160001 784 11722 160001 2922 11722 147572 2922 133420 147572 87336 133420 132109 87336 90155 132109 48288 90155 62732 48288 19769 62732 71849 19769 132724 71849 49916 132724 119484 49916 6527 119484 129727 6527 84927 129727 119327 84927 49884 119327 45116 49884 36387 451...
result:
ok both subtasks are correct!
Test #16:
score: 5
Accepted
time: 7ms
memory: 5740kb
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 1228 60201 220 1228 621 220 13 621 221 13 1234 221 2808 1234 16 2808 231 16 3208 231 232 3208 4812 232 25 4812 627 25 405 627 244 405 29 244 630 29 416 630 824 416 417 824 633 417 1246 633 637 1246 5235 637 246 5235 1011 246 1247 1011 419 1247 250 419 830 250 438 830 252 438 6224 252 253 6224 ...
result:
ok both subtasks are correct!
Test #17:
score: 0
Wrong Answer
time: 10ms
memory: 10904kb
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:
764 1536 2314 3088 3852 4638 5410 6190 6962 7728 8508 9278 10048 10818 11594 12376 13154 13942 14714 15492 16258 17030 17808 18572 19350 20128 20910 21678 22446 23228 24008 24774 25550 26326 27102 27876 28650 29420 30202 30988 31762 32552 33324 34100 34876 35648 36420 37192 37972 38752 39522 40300 4...
result:
wrong answer first subtask is incorrect
Test #18:
score: 5
Accepted
time: 4ms
memory: 8932kb
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 615 120001 1552 615 1216 1552 617 1216 1241 617 26 1241 323 26 28 323 3616 28 43 3616 325 43 48 325 337 48 1554 337 53 1554 5138 53 645 5138 1555 645 1248 1555 351 1248 1253 351 354 1253 1259 354 924 1259 65 924 2444 65 1269 2444 372 1269 66 372 1556 66 647 1556 75 647 649 75 1823 649 1561 182...
result:
ok both subtasks are correct!
Test #19:
score: 0
Runtime Error
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:
result:
Test #20:
score: 5
Accepted
time: 16ms
memory: 10484kb
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 430 160001 2828 430 26 2828 433 26 35 433 856 35 37 856 461 37 1228 461 2033 1228 41 2033 464 41 47 464 1247 47 4837 1247 61 4837 468 61 1630 468 863 1630 67 863 2428 67 867 2428 2064 867 874 2064 1634 874 2831 1634 470 2831 878 470 83 878 1255 83 2434 1255 1651 2434 485 1651 87 485 492 87 89 ...
result:
ok both subtasks are correct!