QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#125875#5280. Depot Rearrangementdengtingyu15 9ms12840kbC++141.3kb2023-07-17 20:31:092023-07-17 20:31:11

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-17 20:31:11]
  • 评测
  • 测评结果:15
  • 用时:9ms
  • 内存:12840kb
  • [2023-07-17 20:31:09]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 810
ll n,m;
ll a[N];
vector<ll>t[N];
ll fir[N],v[N*N],nxt[N*N],w[N*N];ll cnt=0; 
inline void add(ll x,ll y,ll z){
	v[++cnt]=y;w[cnt]=z;nxt[cnt]=fir[x];fir[x]=cnt;
	return ;
}
bool vis[N];
ll xu[N],cn=0;
inline void dfs(ll x){
	vis[x]=1;if(!fir[x])return ;
	ll o=v[fir[x]];xu[++cn]=fir[x];
	fir[x]=nxt[fir[x]];dfs(o);
	return ;
} 
ll x[N*N],y[N*N],cnn=0;
ll tt[N*N];ll ji=0;
int main()
{
//	freopen("test1.in","r",stdin);
	//freopen(".in","r",stdin);
	//freopen("test1.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;ll g=n*m+1;for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)t[j].clear();
		for(int j=1;j<=m;j++){
			cin>>a[j];tt[++ji]=a[j];t[a[j]].push_back(j);
		}for(int j=1;j<=m;j++){
			if(t[j].empty()){
				add(j+n,i,0);continue;
			}for(int k=1;k<t[j].size();k++)add(i,j+n,t[j][k]+(i-1)*m);
		}
	}for(int i=1;i<=n;i++){
		if(vis[i])continue;
		cn=0;dfs(i);if(!cn)continue;
		assert(v[xu[cn]]==i);
		reverse(xu+1,xu+cn);
		x[++cnn]=w[xu[1]];y[cnn]=g;
		for(int i=3;i<=cn;i+=2){
			x[++cnn]=w[xu[i-2]];y[cnn]=w[xu[i]];
		}x[++cnn]=g;y[cnn]=w[xu[cn-1]];
	}cout<<cnn<<'\n';
	for(int i=1;i<=cnn;i++){
		cout<<x[i]<<' '<<y[i]<<'\n';
	}return 0;
}

详细

Test #1:

score: 5
Accepted
time: 1ms
memory: 3480kb

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: 2ms
memory: 9684kb

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
10 21
10 2
2 14
14 7
7 15
15 3
3 18
18 8
8 19
19 12
12 20
20 4
21 4

result:

ok both subtasks are correct!

Test #3:

score: 5
Accepted
time: 2ms
memory: 9732kb

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
18 38
38 29
29 75
75 30
30 90
90 49
49 39
39 20
20 43
43 6
6 28
28 67
67 56
56 66
66 76
76 36
36 16
16 26
26 87
87 97
97 55
55 44
44 27
27 95
95 58
58 79
79 50
50 100
100 89
89 3
101 3

result:

ok both subtasks are correct!

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 9708kb

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:

20
453 1001
453 184
184 734
734 713
713 819
819 359
359 210
210 830
830 670
670 850
850 814
814 949
949 109
1001 109
775 1001
775 175
1001 175
747 1001
747 707
1001 707

result:

wrong answer first subtask is incorrect

Test #5:

score: 0
Wrong Answer
time: 3ms
memory: 9864kb

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:

201
13073 20001
13073 2299
2299 5599
5599 11499
11499 15399
15399 6599
6599 8579
8579 9190
9190 10190
10190 12872
12872 18272
18272 4429
4429 18229
18229 10590
10590 16496
16496 13396
13396 8590
8590 6084
6084 11861
11861 12459
12459 8798
8798 8598
8598 8079
8079 15979
15979 17999
17999 4889
4889 44...

result:

wrong answer first subtask is incorrect

Test #6:

score: 0
Runtime Error

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:


result:


Test #7:

score: 0
Wrong Answer
time: 6ms
memory: 10328kb

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:

235
72662 90001
72662 11820
11820 72720
72720 75733
75733 72733
72733 1262
90001 1262
55164 90001
55164 2064
2064 40016
40016 57387
57387 52287
52287 29694
29694 71905
71905 80995
80995 71995
71995 29605
29605 46592
46592 51995
51995 46595
46595 84512
84512 46712
46712 47192
47192 83192
83192 81409
...

result:

wrong answer first subtask is incorrect

Test #8:

score: 0
Runtime Error

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:


result:


Test #9:

score: 0
Runtime Error

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:


result:


Test #10:

score: 0
Runtime Error

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:


result:


Test #11:

score: 0
Runtime Error

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:


result:


Test #12:

score: 0
Runtime Error

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:


result:


Test #13:

score: 0
Runtime Error

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:


result:


Test #14:

score: 0
Runtime Error

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:


result:


Test #15:

score: 0
Wrong Answer
time: 9ms
memory: 12840kb

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:

242
118784 160001
118784 784
160001 784
11722 160001
11722 2922
2922 147572
147572 3172
160001 3172
48581 160001
48581 36726
36726 150726
150726 152386
152386 48786
48786 98581
98581 9377
9377 3377
160001 3377
20798 160001
20798 16140
16140 75857
75857 25057
25057 88665
88665 77865
77865 138790
1387...

result:

wrong answer first subtask is incorrect

Test #16:

score: 0
Runtime Error

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:


result:


Test #17:

score: 0
Runtime Error

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:


result:


Test #18:

score: 0
Runtime Error

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:


result:


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: 0
Runtime Error

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:


result: