UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209933#3778. 交换乘积cql100242ms5392kbC++11843b2024-08-05 11:17:422024-08-05 12:18:41

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
	int n; cin >> n;
	vector<pair<int, int>> a(n), b(n), c(n), d;
	for (int i = 0; i < n; i++)
		scanf("%lld", &a[i].first);
	d = a;
	for (int i = 0; i < n; i++) {
		scanf("%lld", &b[i].first);
		b[i].second = i;
	}
	sort(b.begin(), b.end());
	sort(a.begin(), a.end());
	int res = 0;
	for (int i = 0; i < n; i++)
		res += a[i].first * b[i].first;
	cout << res << endl;
	for (int i = 0; i < n; i++)
		c[b[i].second] = { a[i].first, b[i].second };
	vector<int> v;
	for (int i = n - 1; i > 0; i--) {
		for (int j = 0; j < i; j++) {
			if (d[j].first == c[i].first) {
				swap(d[j], d[j + 1]);
				v.push_back(j + 1);
			}
		}
	}
	cout << v.size() << endl;
	for (int i = 0; i < v.size(); i++)
		printf("%lld ", v[i]);
	return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 2ms
memory: 1312kb

input:

10
2 6 6 7 7 8 9 9 9 10
1 2 2 2 4 4 4 5 8 9

output:

343
5
7 8 7 4 2 

result:

ok Accepted

Test #2:

score: 10
Accepted
time: 0ms
memory: 1336kb

input:

300
3 7 16 23 27 28 30 31 31 33 39 39 40 41 45 52 54 57 60 76 77 80 82 83 84 87 95 96 99 101 102 102...

output:

100081185
41
296 290 272 266 255 251 247 244 242 235 221 217 212 200 198 182 172 156 144 141 139 114...

result:

ok Accepted

Test #3:

score: 10
Accepted
time: 0ms
memory: 1344kb

input:

1000
5877 11223 46751 56288 84111 90383 107139 123175 189078 189840 201516 206791 212484 235460 2355...

output:

31886434041864508
0

result:

ok Accepted

Test #4:

score: 10
Accepted
time: 0ms
memory: 1588kb

input:

300
850 586 11 803 499 983 491 676 654 701 902 727 76 292 948 875 126 701 815 10 614 170 207 109 3 3...

output:

30126307
22537
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 5...

result:

ok Accepted

Test #5:

score: 10
Accepted
time: 45ms
memory: 3296kb

input:

1000
2303 71258 47543 27966 78350 51973 54564 93554 93120 22126 73773 37093 33624 99015 98835 72871 ...

output:

33644571203
259889
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 3...

result:

ok Accepted

Test #6:

score: 10
Accepted
time: 0ms
memory: 1376kb

input:

100
96840 47122 5255 76197 81892 650 34013 82490 89220 60416 42623 1755 82567 10753 20425 70135 4333...

output:

357435899115
2347
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 6...

result:

ok Accepted

Test #7:

score: 10
Accepted
time: 26ms
memory: 3288kb

input:

800
6547222 7373197 3093209 5574969 3392784 6785440 1906423 4960424 1000638 4591726 9150475 1385022 ...

output:

26926720212052531
159257
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596...

result:

ok Accepted

Test #8:

score: 10
Accepted
time: 43ms
memory: 5392kb

input:

1000
350 868 622 692 210 3582 3414 2296 2391 1002 1607 945 111 478 424 661 3009 2223 2397 2168 1618 ...

output:

5358834254
273678
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 40...

result:

ok Accepted

Test #9:

score: 10
Accepted
time: 82ms
memory: 5388kb

input:

1000
1 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 2 1 2 1 1 1 2 1 1 1 2 1 1 1 1 2 1 2 2 1 2 1 1 1 1 1 1 1 1 1 1...

output:

2507
477847
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 ...

result:

ok Accepted

Test #10:

score: 10
Accepted
time: 44ms
memory: 3300kb

input:

1000
4326892 2791949 5730257 8195022 6651135 6011847 9951798 1049226 2435447 2097834 7158411 7162178...

output:

34200287502289533
258080
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341...

result:

ok Accepted

Extra Test:

score: 0
Extra Test Passed