# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
235165 |
2020-05-27T08:10:30 Z |
Vimmer |
Doktor (COCI17_doktor) |
C++14 |
|
1000 ms |
4216 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 500001
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
typedef long double ld;
typedef long long ll;
typedef short int si;
int a[N], ans, L = 1, R = 1, pr[N];
int main()
{
// freopen("input4.txt", "r", stdin); freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (register int i = 1; i <= n; i++) cin >> a[i];
for (register int i = 1; i <= n; i++)
{
pr[i] = 0;
if (i != 1) pr[i] = pr[i - 1];
if (a[i] == i) pr[i]++;
}
for (register int i = 1; i <= n; i++)
{
int l = a[i], r = i;
if (l > r) swap(l, r);
if (l == r || r - l - (pr[r] - pr[l - 1]) <= ans) continue;
int md = (r + l) >> 1, kol = 0, len = r - l;
for (register int j = l; j <= md; j++)
{
if (j + len == a[j]) kol++;
if (a[j] == j && len != 0) kol--;
len -= 2;
}
if (len == -2) len += 2;
for (register int j = md + 1; j <= r; j++)
{
len += 2;
if (j - len == a[j]) kol++;
if (a[j] == j && len != 0) kol--;
}
if (ans < kol) {ans = kol; L = l; R = r;}
}
cout << a[L] << " " << a[R] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
384 KB |
Output is correct |
2 |
Correct |
7 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
504 KB |
Output is correct |
2 |
Correct |
39 ms |
2680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1091 ms |
1024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
4216 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1089 ms |
2552 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |