# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
82207 |
2018-10-29T13:27:28 Z |
pamaj |
Doktor (COCI17_doktor) |
C++14 |
|
1000 ms |
8620 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 |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
556 KB |
Output is correct |
2 |
Correct |
4 ms |
556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
756 KB |
Output is correct |
2 |
Correct |
7 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
756 KB |
Output is correct |
2 |
Correct |
2 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
872 KB |
Output is correct |
2 |
Execution timed out |
1065 ms |
7124 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
7124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
8620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1080 ms |
8620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |