Submission #82203

# Submission time Handle Problem Language Result Execution time Memory
82203 2018-10-29T13:23:58 Z pamaj Doktor (COCI17_doktor) C++17
50 / 100
1000 ms 9308 KB
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;

int v[maxn], pfsum[maxn] , n;
int pos[maxn];

int main()
{

	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> v[i];
		pos[v[i]] = i;
		if(v[i] == i) 
		{
			pfsum[i] = pfsum[i - 1] + 1;
		}
	}

	vector<pair<int, int>> p;

	for(int i = 1; i <= n; i++)
	{
		if(v[i] == i) continue;
		int ini = v[i], fim = pos[v[i]];
		if(ini > fim) swap(ini, fim);
		p.push_back({ini, fim});
	}

	int best = 0;
	pair<int, int> bp;
	for(auto u : p)
	{

		int ans = 0;
		int i = u.first, j = u.second;
		ans += pfsum[i - 1];
		ans += pfsum[n] - pfsum[j];

		int mid = (u.second - u.first)/2;
		for(int cont = 0; cont < mid; cont++)
		{
			swap(v[u.first + cont], v[u.second - cont]);
		} 
		for(int z = u.first; z <= u.second; z++)
		{
			if(v[z] == z) ans++;
		}
		for(int cont = 0; cont < mid; cont++)
		{
			swap(v[u.first + cont], v[u.second - cont]);
		}
		if(ans > best)
		{
			best = ans;
			bp.first = v[u.first], bp.second = v[u.second];
		}
	}

	//cout << best << "\n";
	if(bp.first == 0 and bp.second == 0) 
	{
		cout << "1 1\n";
		return 0;
	}

	cout << bp.first << " " << bp.second << "\n";

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 508 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 508 KB Output is correct
2 Correct 4 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 712 KB Output is correct
2 Correct 7 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 712 KB Output is correct
2 Correct 2 ms 712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 784 KB Output is correct
2 Execution timed out 1068 ms 7904 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 7904 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 9308 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 9308 KB Time limit exceeded
2 Halted 0 ms 0 KB -