UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#209857#3778. 交换乘积Yhlms10079ms3440kbC++11972b2024-08-05 10:00:142024-08-05 12:13:54

answer

#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
#define int unsigned long long
//fixed << setprecision()
const int length = 1005;
int n;
pair<int, int> a[1005];
pair<int, int> b[1005];
int ans = 0;
int want[length];
int pos[length];
queue<int> q;
signed main()
{
	ios::sync_with_stdio(false);
	ans = 0;
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> a[i].first;
		a[i].second = i;
	}
	for(int i = 1;i <= n;i++)
	{
		cin >> b[i].first;
		b[i].second = i;
	}
	sort(a + 1, a + 1 + n);
	sort(b + 1, b + 1 + n);
	for(int i = 1;i <= n;i++)
	{
		ans += a[i].first * b[i].first;
		want[a[i].second] = b[i].second;
	}
	cout << ans << endl;
	for(int i = n;i >= 1;i--)
	{
		for(int j = 1;j < i;j++)
		{
			if(want[j] > want[j + 1])
			{
				q.push(j);
				swap(want[j], want[j + 1]);
			}
			
		}
	}
	cout << q.size() << endl;
	while(q.size())
	{
		cout << q.front() << " ";
		q.pop();
	}
	return 0;
}

详细

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

Test #1:

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

input:

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

output:

343
0

result:

ok Accepted

Test #2:

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

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
0

result:

ok Accepted

Test #3:

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

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

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
22499
1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 ...

result:

ok Accepted

Test #5:

score: 10
Accepted
time: 18ms
memory: 3440kb

input:

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

output:

33644571203
259882
2 3 5 6 8 9 10 11 12 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...

result:

ok Accepted

Test #6:

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

input:

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

output:

357435899115
2347
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33...

result:

ok Accepted

Test #7:

score: 10
Accepted
time: 16ms
memory: 2380kb

input:

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

output:

26926720212052531
159257
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 ...

result:

ok Accepted

Test #8:

score: 10
Accepted
time: 16ms
memory: 3276kb

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
258108
4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 20 21 22 24 25 26 27 28 30 31 32 33 34 35 3...

result:

ok Accepted

Test #9:

score: 10
Accepted
time: 5ms
memory: 1676kb

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
48290
2 4 5 6 8 9 12 14 15 18 20 21 22 24 25 26 28 29 30 31 33 36 38 39 40 41 42 43 44 45 46 47...

result:

ok Accepted

Test #10:

score: 10
Accepted
time: 20ms
memory: 3280kb

input:

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

output:

34200287502289533
258080
1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 29 30...

result:

ok Accepted

Extra Test:

score: 0
Extra Test Passed