89022024-02-03 18:26:37IgnácLegtöbbször szomszédok (75 pont)cpp17Wrong answer 47/75268ms8392 KiB
// Source: https://usaco.guide/general/io

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

int main() {
	int n, m;
	cin >> n >> m;
	map<int, vector<int>> a;
	map<int, int> dbe, dbm;
	for (int i = 1; i <= m - 1; i++) {
		int pont;
		cin >> pont;
		a[pont].push_back(i);
	}

	int p;
	cin >> p;
	int laste = 100001, lastm = 0;
	for (pair<int, vector<int>> lo : a) {
		if (lo.first > p) laste = lo.first;
		if (lo.first < p && lastm == 0) lastm = lo.first;
	}

	for (int lo : a[laste]) {
		dbe[lo]++;
	}

	for (int lo : a[lastm]) {
		dbm[lo]++;
	}

	vector<int> ee = a[laste], mm = a[lastm];
	for (int i = m + 1; i <= n; i++) {
		int pont;
		cin >> pont;
		if (pont == laste) ee.push_back(i);
		if (pont == lastm) mm.push_back(i);
		if (pont < laste && pont > p) {
			ee = {i};
			laste = pont;
		}

		if (pont > lastm && pont < p) {
			mm = {i};
			lastm = pont;
		}
		for (int lo : ee) dbe[lo]++;
		for (int lo : mm) dbm[lo]++;
	}

	int be = -1;
	for (pair<int, int> lo : dbe) {
		if (lo.second > dbe[be]) be = lo.first;
	}

	if (be == -1) cout << "-1\n";
	else cout << be << " " << dbe[be] << "\n";

	int bm = -1;
	for (pair<int, int> lo : dbm) {
		if (lo.second > dbm[bm]) bm = lo.first;
	}

	if (bm == -1) cout << "-1\n";
	else cout << bm << " " << dbm[bm] << "\n";
}
SubtaskSumTestVerdictTimeMemory
base47/75
1Accepted0/03ms1972 KiB
2Wrong answer0/0148ms2932 KiB
3Accepted2/23ms2728 KiB
4Accepted2/23ms2832 KiB
5Wrong answer0/43ms3044 KiB
6Partially correct2/43ms3260 KiB
7Accepted3/33ms3356 KiB
8Partially correct2/43ms3488 KiB
9Wrong answer0/46ms4572 KiB
10Accepted4/44ms3872 KiB
11Accepted4/46ms4256 KiB
12Accepted4/48ms4156 KiB
13Accepted4/48ms4248 KiB
14Accepted4/48ms4368 KiB
15Accepted4/48ms4444 KiB
16Accepted4/412ms4676 KiB
17Accepted4/414ms5068 KiB
18Accepted4/419ms5364 KiB
19Time limit exceeded0/4261ms4684 KiB
20Time limit exceeded0/4268ms5052 KiB
21Time limit exceeded0/4237ms5164 KiB
22Wrong answer0/448ms8392 KiB