Submission #87686

# Submission time Handle Problem Language Result Execution time Memory
87686 2018-12-01T22:41:33 Z jasony123123 Doktor (COCI17_doktor) C++11
20 / 100
3 ms 828 KB
/*
Mail.Ru Cup 2018 Round 3
https://codeforces.com/contests/1056
*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define vsort(a) sort(a.begin(), a.end());
#define mp make_pair
#define v vector
#define sf scanf
#define pf printf

typedef long long ll;
typedef pair<int, int > pii;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void io();

const int MAXN = 50;

int N;
int A[MAXN];
int pref[MAXN];
v<pii> splits[MAXN * 2];

int main() {

	cin >> N;
	FORE(i, 1, N) {
		cin >> A[i];
		pii swit = { i, A[i] };
		if (i > A[i])
			swap(swit.first, swit.second);
		splits[i + A[i]].push_back(swit);
		pref[i] = pref[i - 1] + (i == A[i] ? 1 : 0);
	}

	int ans = pref[N];
	pii best = { 1,1 };

	FORE(s, 2, 2 * N) if (splits[s].size() > 0) {
		sort(splits[s].begin(), splits[s].end(), greater<pii>());
		FOR(i, 0, splits[s].size()) {
			pii intv = splits[s][i];
			int numG = i + 1 + pref[N] - (pref[intv.second] - pref[intv.first - 1]);
			if (numG > ans) {
				ans = numG;
				best = intv;
			}
		}
	}

	cout << A[best.first] << " " << A[best.second] << "\n";
	return 0;
}













//int N;
//int cnt[1000010];
//int a[500010];
//int mx = 0;
//
//int main() {
//	//io();
//	cin >> N;
//	FORE(i, 1, N) {
//		int val; cin >> val;
//		a[i] = val;
//		cnt[val + i]++;
//		if (cnt[val + i] > cnt[mx])
//			mx = val + i;
//	}
//	double mid = mx / 2.0;
//	double part = min(N - mid, mid - 1);
//	int l = (int)(mid - part), r = (int)(mid + part);
//	cout << a[l] << " " << a[r] << "\n";
//	return 0;
//}


void io() {
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#else
	// online submission
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

Compilation message

doktor.cpp: In function 'void io()':
doktor.cpp:103:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("input.in", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
doktor.cpp:104:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("output.out", "w", stdout);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 552 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 612 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 752 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 816 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -