QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#116093 | #5280. Depot Rearrangement | zhouhuanyi# | 20 | 70ms | 26320kb | C++11 | 1.7kb | 2023-06-28 09:19:07 | 2024-05-31 14:20:31 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#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=1;i<=length;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: 1ms
memory: 7916kb
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: 5868kb
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 4 21 10 4 3 10 15 3 2 15 20 2 8 20 14 8 7 14 19 7 12 19 18 12 21 18
result:
ok both subtasks are correct!
Test #3:
score: 2
Acceptable Answer
time: 1ms
memory: 7816kb
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 6 101 29 6 38 29 18 38 3 18 20 3 39 20 49 39 76 49 43 76 16 43 30 16 90 30 28 90 56 28 67 56 36 67 75 36 67 75 97 67 87 97 27 87 50 27 55 50 100 55 44 100 79 44 58 79 95 58 26 95 90 26 101 90
result:
points 0.40 first subtask is correct but plan is wrong.
Test #4:
score: 2
Acceptable Answer
time: 1ms
memory: 5812kb
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 1001 453 707 1001 747 707 1001 747
result:
points 0.40 first subtask is correct but plan is wrong.
Test #5:
score: 2
Acceptable Answer
time: 2ms
memory: 5964kb
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 273 20001 2648 273 11540 2648 15165 11540 5034 15165 3334 5034 3971 3334 3641 3971 4955 3641 7854 4955 10354 7854 12213 10354 3013 12213 12259 3013 459 12259 17871 459 5065 17871 7398 5065 3761 7398 5861 3761 4233 5861 3784 4233 6061 3784 5159 6061 1488 5159 14250 1488 9050 14250 14288 9050 1459...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #6:
score: 0
Wrong Answer
time: 1ms
memory: 6092kb
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 0 4021 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 417 0 0 417 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 499 0 0 499 380 0 0 380 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 436 0 0 436 0 0 0 0 0 0 0 0 0 0 417 0 0 417 0 0 0 0 636 0 460 636 0 460 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer Integer 0 violates the range [1, 4021]
Test #7:
score: 2
Acceptable Answer
time: 19ms
memory: 6456kb
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 1262 90001 57670 1262 82270 57670 57662 82270 42644 57662 13556 42644 54956 13556 20910 54956 85710 20910 58544 85710 61771 58544 27271 61771 16610 27271 30110 16610 16685 30110 65959 16685 21859 65959 20359 21859 77959 20359 3259 77959 58459 3259 65885 58459 16773 65885 26374 16773 19174 26374 ...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #8:
score: 0
Wrong Answer
time: 3ms
memory: 7692kb
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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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, 12041]
Test #9:
score: 0
Wrong Answer
time: 3ms
memory: 8256kb
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 0 40001 0 0 0 0 0 0 0 0 0 0 701 0 0 701 0 0 0 0 0 0 0 0 1061 0 0 1061 541 0 0 541 0 0 0 0 0 0 0 0 83 0 467 83 539 467 0 539 169 0 0 169 0 0 0 0 0 0 699 0 0 699 701 0 0 701 429 0 67 429 183 67 229 183 701 229 0 701 2943 0 0 2943 0 0 0 0 0 0 0 0 0 0 27 0 225 27 499 225 0 499 0 0 0 0 0 0 713 0 0 ...
result:
wrong answer Integer 0 violates the range [1, 40001]
Test #10:
score: 0
Wrong Answer
time: 2ms
memory: 8072kb
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 0 6401 338 0 0 338 0 0 806 0 977 806 2009 977 15 2009 2238 15 1428 2238 1034 1428 839 1034 234 839 353 234 41 353 276 41 750 276 510 750 1119 510 757 1119 109 757 2417 109 3288 2417 534 3288 1581 534 2337 1581 281 2337 938 281 1025 938 396 1025 191 396 0 191 245 0 1366 245 861 1366 1560 861 180...
result:
wrong answer Integer 0 violates the range [1, 6401]
Test #11:
score: 0
Wrong Answer
time: 8ms
memory: 10108kb
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 0 40001 0 0 179 0 0 179 437 0 0 437 0 0 177 0 0 177 0 0 0 0 0 0 0 0 69 0 0 69 0 0 0 0 0 0 0 0 547 0 0 547 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 287 0 0 287 0 0 0 0 0 0 0 0 0 0 535 0 213 535 0 213 0 0 0 0 67 0 0 67 0 0 359 0 0 359 0 0 0 0 0 0 759 0 0 759 0 0 0 0 0 0 0 0 441 0 0 441 0 0 0 0 533 0 0 53...
result:
wrong answer Integer 0 violates the range [1, 40001]
Test #12:
score: 0
Wrong Answer
time: 2ms
memory: 8456kb
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 397 0 0 397 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 103 0 0 103 0 0 817 0 0 817 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 103 0 0 103 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: 30ms
memory: 13060kb
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 181 90001 833 181 0 833 0 0 1745 0 289 1745 2541 289 609 2541 3215 609 0 3215 75 0 1045 75 0 1045 2083 0 0 2083 1405 0 5451 1405 901 5451 0 901 0 0 0 0 787 0 375 787 1237 375 171 1237 3363 171 0 3363 87 0 865 87 145 865 539 145 2083 539 0 2083 1467 0 1123 1467 483 1123 2335 483 93 2335 919 93 ...
result:
wrong answer Integer 0 violates the range [1, 90001]
Test #14:
score: 0
Wrong Answer
time: 44ms
memory: 16040kb
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 363 80401 737 363 275 737 1173 275 253 1173 1565 253 1921 1565 245 1921 1875 245 701 1875 941 701 1487 941 2279 1487 209 2279 2267 209 659 2267 1361 659 2619 1361 133 2619 2571 133 411 2571 1871 411 895 1871 0 895 2195 0 0 2195 2195 0 0 2195 3399 0 117 3399 3081 117 1077 3081 63 1077 3391 63 4...
result:
wrong answer Integer 0 violates the range [1, 80401]
Test #15:
score: 2
Acceptable Answer
time: 42ms
memory: 8004kb
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 784 160001 118784 784 160001 118784 2922 160001 11722 2922 3172 11722 115020 3172 45736 115020 12909 45736 132351 12909 94351 132351 8955 94351 90073 8955 83273 90073 83888 83273 48288 83888 90155 48288 119963 90155 33061 119963 7861 33061 139569 7861 36721 139569 126703 36721 47903 126703 29909...
result:
points 0.40 first subtask is correct but plan is wrong.
Test #16:
score: 0
Wrong Answer
time: 12ms
memory: 9672kb
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 133 60201 795 133 0 795 0 0 0 0 0 0 0 0 0 0 0 0 439 0 0 439 731 0 575 731 0 575 0 0 1955 0 0 1955 1939 0 0 1939 0 0 2123 0 0 2123 0 0 2587 0 0 2587 6513 0 0 6513 0 0 2695 0 0 2695 0 0 7195 0 0 7195 0 0 0 0 0 0 3847 0 0 3847 0 0 1457 0 0 1457 0 0 8349 0 0 8349 0 0 4767 0 0 4767 0 0 1939 0 0 193...
result:
wrong answer Integer 0 violates the range [1, 60201]
Test #17:
score: 0
Wrong Answer
time: 45ms
memory: 17900kb
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 389 80401 849 389 349 849 1579 349 273 1579 1969 273 201 1969 2067 201 177 2067 2771 177 173 2771 2945 173 169 2945 3577 169 0 3577 3863 0 0 3863 0 0 0 0 4755 0 0 4755 5049 0 0 5049 5475 0 0 5475 5815 0 655 5815 0 655 1575 0 663 1575 0 663 1955 0 0 1955 0 0 659 0 0 659 1955 0 0 1955 845 0 0 84...
result:
wrong answer Integer 0 violates the range [1, 80401]
Test #18:
score: 0
Wrong Answer
time: 36ms
memory: 14944kb
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 293 120001 501 293 265 501 493 265 1799 493 801 1799 1217 801 0 1217 497 0 721 497 261 721 4037 261 1393 4037 4545 1393 485 4545 897 485 0 897 1385 0 1747 1385 893 1747 4581 893 2611 4581 0 2611 889 0 0 889 1087 0 487 1087 1309 487 5375 1309 2245 5375 0 2245 3859 0 0 3859 4381 0 0 4381 2241 0 ...
result:
wrong answer Integer 0 violates the range [1, 120001]
Test #19:
score: 0
Wrong Answer
time: 70ms
memory: 26320kb
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 327 132868 777 327 1193 777 1579 1193 249 1579 1571 249 773 1571 1567 773 1993 1567 245 1993 1965 245 765 1965 1825 765 1155 1825 1795 1155 2389 1795 241 2389 2343 241 757 2343 2229 757 1133 2229 2339 1133 237 2339 2767 237 233 2767 2961 233 1563 2961 2279 1563 753 2279 2647 753 749 2647 2957...
result:
wrong answer Integer 0 violates the range [1, 132868]
Test #20:
score: 0
Wrong Answer
time: 60ms
memory: 17284kb
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 799 147 1441 799 775 1441 2343 775 69 2343 1975 69 579 1975 355 579 1059 355 4117 1059 2135 4117 1975 2135 1563 1975 1163 1563 0 1163 5229 0 3063 5229 0 3063 0 0 0 0 0 0 0 0 689 0 2393 689 3165 2393 177 3165 2965 177 1359 2965 75 1359 0 75 13481 0 4781 13481 14171 4781 4991 14171 15...
result:
wrong answer Integer 0 violates the range [1, 160001]