QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116094 | #5280. Depot Rearrangement | zhouhuanyi# | 35 | 74ms | 25296kb | C++11 | 1.7kb | 2023-06-28 09:21:32 | 2024-05-31 14:20:32 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cassert>
#define N 800
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
struct reads
{
int num,data;
};
struct node
{
int x,y;
};
node st[N*N+1];
int n,m,leng,lengths,res,a[N*N+1],cnt[N+1],cur[N+1],tong[N+1],length;
vector<reads>E[N+1];
bool used[N*N+1];
void add(int x,int y)
{
++leng,E[x].push_back((reads){y,leng});
return;
}
void adder(int x,int y)
{
st[++lengths]=(node){x,y},swap(a[x],a[y]);
return;
}
void dfs(int x)
{
for (int &i=cur[x];i<E[x].size();++i)
if (!used[E[x][i].data])
used[E[x][i].data]=1,dfs(E[x][i].num),tong[++length]=x;
return;
}
int main()
{
int x,rt;
vector<int>A;
vector<int>B;
n=read(),m=read();
for (int i=1;i<=n*m;++i) a[i]=read();
for (int i=1;i<=m;++i)
{
A.clear(),B.clear();
for (int j=1;j<=n;++j) cnt[j]=0;
for (int j=1;j<=n*m;++j)
if (a[j]==i)
cnt[(j-1)/m+1]++;
for (int j=1;j<=n;++j)
{
if (cnt[j]>1)
{
for (int k=1;k<=cnt[j]-1;++k) add(j,n+i);
}
else if (!cnt[j]) add(n+i,j);
}
}
for (int i=1;i<=n;++i)
{
length=0,dfs(i);
if (length)
{
reverse(tong+1,tong+length+1),rt=n*m+1;
for (int i=length-1;i>=1;i-=2)
{
x=0;
for (int j=(tong[i]-1)*m+1;j<=tong[i]*m;++j)
if (a[j]==tong[i+1]-n)
x=j;
adder(x,rt),rt=x;
}
adder(n*m+1,rt);
}
}
printf("%d\n",lengths);
for (int i=1;i<=lengths;++i) printf("%d %d\n",st[i].x,st[i].y);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 6088kb
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: 7888kb
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 20 21 12 20 19 12 8 19 15 8 7 15 18 7 4 18 14 4 3 14 10 3 2 10 21 2
result:
ok both subtasks are correct!
Test #3:
score: 5
Accepted
time: 1ms
memory: 7856kb
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 89 101 27 89 100 27 58 100 79 58 50 79 95 50 55 95 44 55 26 44 87 26 97 87 66 97 76 66 36 76 67 36 56 67 28 56 90 28 30 90 16 30 43 16 75 43 49 75 39 49 20 39 3 20 18 3 38 18 29 38 6 29 101 6
result:
ok both subtasks are correct!
Test #4:
score: 5
Accepted
time: 0ms
memory: 8192kb
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 949 814 359 949 775 359 670 775 830 670 175 830 210 175 850 210 734 850 713 734 819 713 109 819 1001 109 747 1001 707 747 1001 707
result:
ok both subtasks are correct!
Test #5:
score: 5
Accepted
time: 2ms
memory: 8136kb
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 16173 20001 16836 16173 6330 16836 17229 6330 15566 17229 16366 15566 18966 16366 7068 18966 17774 7068 9994 17774 18899 9994 19184 18899 19682 19184 4482 19682 18968 4482 18781 18968 10381 18781 18466 10381 18091 18466 18491 18091 10488 18491 18488 10488 2866 18488 17266 2866 19529 17266 12730 ...
result:
ok both subtasks are correct!
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 8092kb
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 3874 4021 4015 3874 3994 4015 4020 3994 3992 4020 3932 3992 3977 3932 3914 3977 3966 3914 3940 3966 3913 3940 4000 3913 3832 4000 3898 3832 3910 3898 3957 3910 3798 3957 3908 3798 3999 3908 3980 3999 3835 3980 3794 3835 3979 3794 3749 3979 3936 3749 3872 3936 3758 3872 3790 3758 3731 3790 3774 ...
result:
wrong answer Integer 0 violates the range [1, 4021]
Test #7:
score: 5
Accepted
time: 13ms
memory: 8428kb
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 75733 72662 37143 75733 87877 37143 84877 87877 35684 84877 60545 35684 87208 60545 88791 87208 5865 88791 40307 5865 69710 40307 15410 69710 49695 15410 15495 49695 5807 15495 16382 5807 22382 16382 80196 22382 22296 80196 88665 22296 19994 88665 79980 19994 66480 79980 81409 66480 ...
result:
ok both subtasks are correct!
Test #8:
score: 0
Wrong Answer
time: 3ms
memory: 7792kb
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 0 12041 0 0 0 0 0 0 0 0 0 0 0 0 11581 0 0 11581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11581 0 0 11581 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11581 0 0 1158...
result:
wrong answer Integer 0 violates the range [1, 12041]
Test #9:
score: 0
Wrong Answer
time: 7ms
memory: 10480kb
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 39699 40001 39983 39699 39588 39983 39958 39588 39631 39958 39368 39631 39799 39368 39278 39799 39952 39278 39173 39952 39476 39173 39293 39476 38966 39293 39797 38966 39587 39797 39626 39587 38565 39626 39934 38565 39459 39934 39022 39459 39988 39022 39046 39988 39867 39046 39037 39867 39775 ...
result:
wrong answer Integer 0 violates the range [1, 40001]
Test #10:
score: 0
Wrong Answer
time: 2ms
memory: 6044kb
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 5423 6401 5598 5423 6238 5598 6400 6238 5465 6400 5920 5465 6231 5920 4794 6231 5917 4794 4636 5917 5119 4636 3040 5119 5754 3040 5912 5754 4159 5912 5439 4159 3836 5439 5435 3836 6393 5435 5425 6393 2868 5425 4561 2868 4957 4561 6080 4957 4787 6080 3360 4787 5417 3360 4140 5417 5117 4140 5907 ...
result:
wrong answer Integer 0 violates the range [1, 6401]
Test #11:
score: 0
Wrong Answer
time: 3ms
memory: 8256kb
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 39795 40001 39873 39795 39724 39873 39936 39724 39657 39936 39995 39657 39776 39995 39665 39776 39956 39665 39774 39956 39994 39774 39566 39994 39659 39566 39266 39659 39639 39266 39992 39639 39390 39992 39551 39390 38947 39551 39537 38947 38588 39537 39519 38588 39984 39519 39656 39984 39368 ...
result:
wrong answer Integer 0 violates the range [1, 40001]
Test #12:
score: 0
Wrong Answer
time: 1ms
memory: 6456kb
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 0 6021 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Integer 0 violates the range [1, 6021]
Test #13:
score: 0
Wrong Answer
time: 26ms
memory: 13040kb
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 89593 90001 89398 89593 89986 89398 88738 89986 89998 88738 89694 89998 86694 89694 89691 86694 89912 89691 89370 89912 87894 89370 88198 87894 88785 88198 89562 88785 88035 89562 89492 88035 89080 89492 89663 89080 88775 89663 86697 88775 89254 86697 88628 89254 88478 88628 89622 88478 89906 ...
result:
wrong answer Integer 0 violates the range [1, 90001]
Test #14:
score: 0
Wrong Answer
time: 37ms
memory: 16412kb
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 80228 80401 0 80228 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77392 0 0 77392 0 0 0 0 0 0 79092 0 0 79092 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 79092 0 0 79092 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 79092 0 0 79092 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Integer 0 violates the range [1, 80401]
Test #15:
score: 5
Accepted
time: 38ms
memory: 8140kb
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 147572 160001 133420 147572 87336 133420 132109 87336 148555 132109 134930 148555 126916 134930 143716 126916 110130 143716 119755 110130 53963 119755 117163 53963 139563 117163 138000 139563 152588 138000 133788 152588 34188 133788 83080 34188 34280 83080 103...
result:
ok both subtasks are correct!
Test #16:
score: 0
Wrong Answer
time: 12ms
memory: 11688kb
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 56994 60201 58368 56994 59793 58368 59577 59793 59788 59577 60185 59788 58974 60185 59772 58974 58776 59772 59391 58776 59979 59391 58273 59979 58972 58273 58181 58972 58962 58181 57185 58962 59159 57185 56573 59159 59761 56573 58379 59761 59365 58379 56040 59365 58177 56040 59190 58177 58370 ...
result:
wrong answer Integer 0 violates the range [1, 60201]
Test #17:
score: 0
Wrong Answer
time: 42ms
memory: 20016kb
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 0 80401 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Integer 0 violates the range [1, 80401]
Test #18:
score: 0
Wrong Answer
time: 39ms
memory: 14880kb
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 118794 120001 118345 118794 119001 118345 116043 119001 117862 116043 118795 117862 118197 118795 119654 118197 118491 119654 114597 118491 117284 114597 113700 117284 117168 113700 116376 117168 119982 116376 117294 119982 113293 117294 115798 113293 116951 115798 116334 116951 112499 116334 ...
result:
wrong answer Integer 0 violates the range [1, 120001]
Test #19:
score: 0
Wrong Answer
time: 74ms
memory: 25296kb
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 0 132868 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 130080 0 0 130080 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 130648 0 0 130648 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 130648 0 0 130648 130080 0 0 130080 0 0 0 0 130080 0 0 130080 0 0 0 0 0 0 0 0 0 0 0 0 128026...
result:
wrong answer Integer 0 violates the range [1, 132868]
Test #20:
score: 0
Wrong Answer
time: 63ms
memory: 16660kb
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 153428 160001 159158 153428 160000 159158 157793 160000 158798 157793 159997 158798 158393 159997 158794 158393 158199 158794 159518 158199 155595 159518 156224 155595 158598 156224 154800 158598 159594 154800 155146 159594 156577 155146 159024 156577 159991 159024 156392 159991 155998 156392 ...
result:
wrong answer Integer 0 violates the range [1, 160001]