QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#57828#4925. Adjacent Pairscheems_is_hiring0 0ms3528kbC++1.4kb2022-10-23 02:48:172022-10-23 02:48:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-23 02:48:18]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3528kb
  • [2022-10-23 02:48:17]
  • 提交

answer

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ii pair<int,int>
const int mod = 1e9 + 7;
const int inf = 2e9 + 9;
const int N = 2e5 + 9;
int f(priority_queue<ii> pq1, priority_queue<ii> pq2) {
	int ans = 0;
	while(pq1.size()) {
		ii v1 = pq1.top();
		int frec1 = v1.first, val1 = v1.second;
		
		ii v2 = pq2.top();
		int frec2 = v2.first, val2 = v2.second;
		
		if(val1 != val2) {
 			//cout << "frec1 " << frec1 << " frec2 " << frec2 << endl;
			return frec1 + frec2;
		}
		else {
			pq2.pop();
			ii v22 = pq2.top();
			frec2 = v22.first;
			//cout << "frec1 " << frec1 << " frec2 " << frec2 << endl;
			return frec1 + frec2;
			pq2.push(v2);	
		}
		// consultar el primer valor de la pq2, si el valor es igual a mi, entonces ir al otro
		
		pq1.pop();
	}
}
void sol() {
	int n; cin >> n;
	map<int,int> M1, M2;
	set<int> S1, S2;
	for(int i = 0 ; i < n ; i ++) {
		int x; cin >> x;
		if(i % 2 == 0) M1[x] ++, S1.insert(x);
		else 		   M2[x] ++, S2.insert(x);
	}
	priority_queue<ii> pq1, pq2;
	for(int x : S1) {
		pq1.push(ii(M1[x], x));
	}
	for(int x : S2) {
		pq2.push(ii(M2[x], x));
	}
	int ans1 = f(pq1, pq2);
	int ans2 = f(pq2, pq1);
	int a = (n / 2), b = n - a;
	
	cout << a + b - min(ans1, ans2) << endl;
	
}
int main() {
	int t; cin >> t;
	while(t --) sol();
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 3476kb

input:

2
5
4 5 2 4 5
2
1 2

output:

3
0

result:

ok 2 lines

Test #2:

score: -20
Wrong Answer
time: 0ms
memory: 3528kb

input:

1
9
1 2 1 2 3 1 2 1 2

output:

5

result:

wrong answer 1st lines differ - expected: '6', found: '5'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%