Submission #235181

# Submission time Handle Problem Language Result Execution time Memory
235181 2020-05-27T08:38:13 Z Vimmer Doktor (COCI17_doktor) C++14
70 / 100
1000 ms 8172 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], an, L = 1, R = 1, ans[N], pos[N];

bool cmp(int x, int y) {return abs(pos[x] - x) > abs(pos[y] - y);}

int main()
{
   // freopen("input.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;

    vector <int> gn; gn.clear();

    for (register int i = 1; i <= n; i++) {gn.pb(i); cin >> a[i]; pos[a[i]] = i; ans[i] = -1;}

    sort(gn.begin(), gn.end(), cmp);

    for (auto it : gn)
    {
        if (ans[it] != -1)
        {
            if (ans[it] > an)
            {
                an = ans[it];

                L = it; R = pos[it];

                if (L > R) swap(L, R);
            }

            continue;
        }

        int l = it, r = pos[it];

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

        if (l == r || r - l <= an) continue;

        register int curl, curr, kol = 0;

        if ((r - l) % 2) {curl = (r + l) / 2; curr = curl + 1;}
          else {curl = ((r + l) / 2) - 1; curr = curl + 2;}

        while (l <= curl && curr <= r)
        {
            if (a[curl] == curl) kol--;

            if (a[curr] == curr) kol--;

            if (a[curr] == curl) kol++;

            if (a[curl] == curr) kol++;

            if (a[curr] == curl) ans[curl] = kol;

            if (a[curl] == curr) ans[curr] = kol;

            curl--; curr++;
        }

        if (kol > an)
        {
            an = kol;

            L = l; R = r;
        }
    }

    cout << a[L] << " " << a[R] << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 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 4 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 432 KB Output is correct
2 Correct 6 ms 436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 512 KB Output is correct
2 Correct 7 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 640 KB Output is correct
2 Correct 114 ms 5624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 1920 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 8172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1094 ms 5724 KB Time limit exceeded
2 Halted 0 ms 0 KB -