Submission #886699

# Submission time Handle Problem Language Result Execution time Memory
886699 2023-12-12T16:57:53 Z vjudge1 Doktor (COCI17_doktor) C++17
30 / 100
1000 ms 2140 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

#define ONLINE_JUDGE
void solve() {
    int n;
    cin >> n;

    vector <int> a(n +1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    auto rev = [&](int l, int r) -> void {
        while(l <= r) {
            swap(a[l], a[r]);
            r--;
            l++;
        }

        return;
    };
    
    array <int, 3> ans = {-1, 0, 0};
    for(int l = 1; l <= n; l++) {
        for(int r = l; r <= n; r++) {
            rev(l, r);

            int cnt = 0;
            for(int i = 1; i <= n; i++) {
                cnt += (a[i] == i);
            }

            rev(l, r);

            if(cnt > ans[0]) {
                ans = {cnt, a[l], a[r]};
            }
        }
    }

    cout << ans[1] << " " << ans[2];

    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 448 KB Output is correct
2 Correct 28 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1029 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1097 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1020 ms 344 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1030 ms 600 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1038 ms 2140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1020 ms 1368 KB Time limit exceeded
2 Halted 0 ms 0 KB -