Submission #792362

# Submission time Handle Problem Language Result Execution time Memory
792362 2023-07-25T03:20:35 Z Nhoksocqt1 Doktor (COCI17_doktor) C++17
0 / 100
123 ms 35020 KB
#include<bits/stdc++.h>
using namespace std;

#define inf 0x3f3f3f3f
#define sz(x) int((x).size())
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

template<class X, class Y>
	inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);}
template<class X, class Y>
	inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int Random(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

const int MAXN = 500005;

vector<int> B[MAXN];
int a[MAXN], sum[MAXN], cnt[4 * MAXN], nArr;

void process() {
    cin >> nArr;
    for (int i = 1; i <= nArr; ++i) {
        cin >> a[i];
        B[max(i, a[i])].push_back(min(i, a[i]));
    }

    int maxcnt(0), l(1), r(1);
    for (int i = 1; i <= nArr; ++i) {
        sum[i] = sum[i - 1];
        for (int it = 0; it < sz(B[i]); ++it) {
            int j(B[i][it]);
            if(i != j) {
                ++cnt[i - 3 * j + 2 * MAXN];
                int midc = ((i - j + 1) & 1) ? (a[j + (i - j + 1) / 2] == (j + (i - j + 1) / 2)) : 0;
                //cout << j << ' ' << i << ' ' << 3 * i - j << ' ' << cnt[3 * i - j + MAXN] << '\n';
                if(maxcnt < cnt[i - 3 * j + 2 * MAXN] - sum[i] + sum[j - 1] + midc) {
                    maxcnt = cnt[i - 3 * j + 2 * MAXN] - sum[i] + sum[j + 1] + midc;
                    l = j, r = i;
                }
            } else {
                ++sum[i];
            }
        }
    }

    if(maxcnt < sum[nArr]) {
        maxcnt = sum[nArr];
        l = r = 1;
    }

    cout << a[l] << ' ' << a[r] << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    process();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 11988 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12072 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 12116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 12500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 16240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 123 ms 35020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -