Submission #381648

# Submission time Handle Problem Language Result Execution time Memory
381648 2021-03-25T12:31:43 Z AdiZer0 Doktor (COCI17_doktor) C++17
0 / 100
675 ms 40808 KB
#include <bits/stdc++.h>

#define pb push_back
#define whole(x) x.begin(), x.end()
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = (int)5e5 + 7;
const int INF = (int)1e9 + 7;
const ll linf = (ll)1e18 + 1;

bool cmp(pair<int, int> a, pair<int, int> b) { 
    return a.second - a.first + 1 < b.second - b.first + 1;
}

int a[N];
ll pref[N];
map<pair<int, int>, int> mp;

int main() {
    int n; scanf ("%d", &n);
    vector<pair<int, int>> v;
    for (int i = 1; i <= n; ++i) { 
        scanf ("%d", a + i);
        if (i == a[i]) pref[i] = 1;
        pref[i] += pref[i - 1];
        v.pb({min(i, a[i]), max(i, a[i])});
    }
    sort(whole(v), &cmp);
    int ansL = 1, ansR = 1;
    int ans = pref[n];
    for (int i = 0; i < n; ++i) { 
        mp[{v[i].first, v[i].second}]++;
        int cur = pref[n] - (pref[v[i].second] - pref[(v[i].first - 1)]);
        if (cur + mp[{v[i].first, v[i].second}] > ans) { 
            ans = cur + mp[{v[i].first, v[i].second}];
            ansL = a[v[i].first], ansR = a[v[i].second];
        }
    }
    printf ("%d %d\n", ansL, ansR);
    return 0;
}

Compilation message

doktor.cpp: In function 'int main()':
doktor.cpp:25:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   25 |     int n; scanf ("%d", &n);
      |            ~~~~~~^~~~~~~~~~
doktor.cpp:28:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         scanf ("%d", a + i);
      |         ~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 7776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 675 ms 40808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 421 ms 24020 KB Output isn't correct
2 Halted 0 ms 0 KB -