Submission #82208

# Submission time Handle Problem Language Result Execution time Memory
82208 2018-10-29T13:28:29 Z pamaj Doktor (COCI17_doktor) C++14
60 / 100
1000 ms 8580 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) 
	{
		for(int i = 1; i <= n; i++)
		{
			if(v[i] == i) cout << i << " " << i << "\n";
			return 0;		
		}
	}

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

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 456 KB Output is correct
2 Correct 2 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 544 KB Output is correct
2 Correct 5 ms 544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 692 KB Output is correct
2 Correct 7 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 820 KB Output is correct
2 Correct 2 ms 820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 824 KB Output is correct
2 Execution timed out 1071 ms 7204 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1058 ms 7204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 8580 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 8580 KB Time limit exceeded
2 Halted 0 ms 0 KB -