89052024-02-03 18:42:32IgnácLegtöbbször szomszédok (75 pont)cpp17Elfogadva 75/7556ms14372 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 + 1 - ie;
	for (int lo : mm) dbm[lo] += n + 1 - 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";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base75/75
1Elfogadva0/03ms1808 KiB
2Elfogadva0/028ms2492 KiB
3Elfogadva2/23ms2272 KiB
4Elfogadva2/23ms2516 KiB
5Elfogadva4/43ms2756 KiB
6Elfogadva4/43ms2920 KiB
7Elfogadva3/33ms2996 KiB
8Elfogadva4/43ms2964 KiB
9Elfogadva4/47ms3836 KiB
10Elfogadva4/44ms3064 KiB
11Elfogadva4/44ms3312 KiB
12Elfogadva4/48ms3364 KiB
13Elfogadva4/48ms3364 KiB
14Elfogadva4/48ms3492 KiB
15Elfogadva4/48ms3708 KiB
16Elfogadva4/410ms3784 KiB
17Elfogadva4/414ms3788 KiB
18Elfogadva4/417ms3916 KiB
19Elfogadva4/456ms14172 KiB
20Elfogadva4/454ms14100 KiB
21Elfogadva4/454ms14372 KiB
22Elfogadva4/441ms6572 KiB