QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#479188#4925. Adjacent PairsNevll#0 1ms3804kbC++141.3kb2024-07-15 15:47:372024-07-15 15:47:37

Judging History

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

  • [2024-07-15 15:47:37]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3804kb
  • [2024-07-15 15:47:37]
  • 提交

answer

# include <bits/stdc++.h>
# define ll long long
# define ld double
# define fi first
# define se second
# define pii pair<int, int>
# define pll pair<ll, ll>
using namespace std;

int main() {
	int cases;
	scanf("%d", &cases);
	while(cases--) {
		int N;
		scanf("%d", &N);
		map<int, int> M1, M2;
		map<pii, int> M3;
		
		int a1 = 0, a2 = 0;
		vector<int> arr(N);
		for(int i=0;i<N;i++) {
			scanf("%d", &arr[i]);
			if(i%2 == 1) {
				M1[arr[i]]++;
			//	cout<<"add : "<<arr[i]<<" "<<arr[i - 1]<<endl;
				M3[{arr[i], arr[i - 1]}]++;
			//	cout<<M3[{2, 5}]<<" "<<M3[{5, 2}]<<endl;
			} else {
				M2[arr[i]]++;
				if(i > 0) M3[{arr[i - 1], arr[i]}]++;
			}
			
		}
		vector<pii> c1, c2;
		c1.clear();
		c2.clear();
		
		for(auto p : M1) c1.push_back(p);
		for(auto p : M2) c2.push_back(p);
		
		c1.push_back({-1, 0});
		c2.push_back({-2, 0});
		
		sort(c1.begin(), c1.end());
		sort(c2.begin(), c2.end());
		
		int ans = 1e9;
		for(int i=c1.size()-1;i>=0;i--) {
			for(int k=c2.size()-1;k>=0;k--) {
				if(c1[i].fi == c2[k].fi) continue;
				
				int val = M3[{c1[i].fi, c2[k].fi}];
			//	cout<<"val ; "<<c1[i].fi<<" "<<c2[k].fi<<" "<<val<<endl;
				int as = N - c1[i].se - c2[k].se + val;
				ans = min(ans, as);
				if(val == 0) break;
			}
		}
		
		printf("%d\n", ans);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3804kb

input:

2
5
4 5 2 4 5
2
1 2

output:

4
1

result:

wrong answer 1st lines differ - expected: '3', found: '4'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%