89042024-02-03 18:39:36IgnácLegtöbbször szomszédok (75 pont)cpp17Partially correct 29/7561ms14868 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 == 100001) laste = lo.first;
		if (lo.first < p) 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];
	int ie = m, im = m;
	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) {
			for (int lo : ee) dbe[lo] += i - ie;
			ie = i;
			ee = {i};
			laste = pont;
		}

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

	for (int lo : ee) dbe[lo] += n - ie;
	for (int lo : mm) dbm[lo] += n - im;
	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
base29/75
1Accepted0/03ms1816 KiB
2Accepted0/029ms2476 KiB
3Partially correct1/23ms2380 KiB
4Partially correct1/22ms2328 KiB
5Partially correct2/43ms2524 KiB
6Accepted4/43ms2616 KiB
7Partially correct1/33ms2740 KiB
8Partially correct2/43ms2952 KiB
9Accepted4/47ms3904 KiB
10Wrong answer0/44ms3024 KiB
11Partially correct2/44ms3156 KiB
12Wrong answer0/48ms3372 KiB
13Wrong answer0/48ms3460 KiB
14Partially correct2/48ms3456 KiB
15Wrong answer0/48ms3568 KiB
16Wrong answer0/412ms3684 KiB
17Wrong answer0/414ms3568 KiB
18Wrong answer0/417ms3572 KiB
19Partially correct2/461ms13880 KiB
20Partially correct2/457ms14336 KiB
21Partially correct2/459ms14868 KiB
22Accepted4/443ms7292 KiB