Submission #235162

# Submission time Handle Problem Language Result Execution time Memory
235162 2020-05-27T08:06:42 Z Vimmer Doktor (COCI17_doktor) C++14
60 / 100
1000 ms 2296 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;

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 (int i = 1; i <= n; i++) cin >> a[i];

    for (int i = 1; i <= n; i++)
    {
        int l = a[i], r = i;

        if (l > r) swap(l, r);

        if (l == r) continue;

        int md = (r + l) >> 1, kol = 0, len = r - l;

        for (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 (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 15 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 384 KB Output is correct
2 Execution timed out 1099 ms 1504 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 640 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 2296 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1092 ms 1400 KB Time limit exceeded
2 Halted 0 ms 0 KB -