Submission #235167

# Submission time Handle Problem Language Result Execution time Memory
235167 2020-05-27T08:12:57 Z Vimmer Doktor (COCI17_doktor) C++14
60 / 100
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 = (pr[r] - pr[l - 1]), len = r - l;

        if ((r - l + 1) % 2 != 0 && a[md] == md) kol++;

        for (register int j = l; j <= md; j++)
        {
            if (len != 0 && j + len == a[j]) kol++;

            if (len != 0 && a[j + len] == j) kol++;

            len -= 2;
        }

        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 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 6 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 40 ms 384 KB Output is correct
2 Correct 40 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 1024 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 4216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1086 ms 2552 KB Time limit exceeded
2 Halted 0 ms 0 KB -