QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#479313#4925. Adjacent PairsNevll#0 0ms4080kbC++141.6kb2024-07-15 16:20:522024-07-15 16:20:53

Judging History

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

  • [2024-07-15 16:20:53]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:4080kb
  • [2024-07-15 16:20:52]
  • 提交

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, vector<int> > M3;
		
		int a1 = 0, a2 = 0;
		vector<int> arr(N);
		
		pii bf = {-1, -1};
		
		for(int i=0;i<N;i++) {
			scanf("%d", &arr[i]);
			if(i%2 == 1) {
				M1[arr[i]]++;
				if(i > 0) M3[{arr[i], arr[i - 1]}].push_back(i - 1);
			} else {
				M2[arr[i]]++;
				if(i > 0) M3[{arr[i - 1], arr[i]}].push_back(i - 1);
			}
		}
		
		map<pii, int> res;
		for(auto p : M3) {
			int ct = 0, cnt = 0;
			for(int k=0;k<p.se.size();k++) {
				if(cnt == 0) cnt += 2;
				else if(p.se[k] == p.se[k - 1] + 1) cnt++;
				else {
					ct += cnt / 2;
					cnt = 2;
				}
			}
			ct += cnt / 2;
			res[p.fi] = ct;
		}
		
		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 = res[{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);
	}
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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%