9422022-02-02 22:23:47nmarciKazamatacpp11Time limit exceeded 0/40301ms10248 KiB
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <list>
using namespace std;
using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    for(auto& i : v){
        cin >> i;
    }
    int reset = 0;
    set<int> keys;
    for(int i = 0; i < n; ++i){
        keys.insert(v[i]);
        cerr << "hely: " << i << " " << reset << endl;
        auto q = keys.upper_bound(i);
        //if(q != keys.begin()) --q;
        auto w = keys.lower_bound((n + i - reset) % n);
        bool ok = false;
        if(i > reset){
            ok = q != w;
        }
        else{
            ok = (w != keys.end()) || *keys.begin() <= i;
        }
        if(/*keys.find((n + i - reset) % n) == keys.end() *keys.lower_bound((n + i - reset) % n) > i 
            && (*keys.lower_bound((n + i - reset) % n) + reset) % n < i*/ !ok){
            int target = (n + i - reset) % n;
            cerr << target << endl;
            auto p = keys.upper_bound(target);
            if(p != keys.begin()){
                --p;
                cerr << min(n - *keys.rbegin() + target, target - *p) << endl;
                reset += min(n - *keys.rbegin() + target, target - *p);
            }
            else{
                cerr << "else " << " " << n - *keys.rbegin() + target << endl;
                reset += (n - *keys.rbegin() + target);
            }
        }
    }
    cout << reset << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Accepted0/02ms1740 KiB
2Time limit exceeded0/0293ms2720 KiB
3Wrong answer0/21ms2132 KiB
4Wrong answer0/21ms2132 KiB
5Wrong answer0/22ms2144 KiB
6Wrong answer0/22ms2148 KiB
7Wrong answer0/27ms2184 KiB
8Wrong answer0/26ms2180 KiB
9Wrong answer0/26ms2196 KiB
10Wrong answer0/27ms2188 KiB
11Time limit exceeded0/2296ms3880 KiB
12Time limit exceeded0/2301ms4236 KiB
13Time limit exceeded0/2293ms4876 KiB
14Time limit exceeded0/2279ms5352 KiB
15Time limit exceeded0/2296ms6112 KiB
16Time limit exceeded0/2300ms6588 KiB
17Time limit exceeded0/2296ms7156 KiB
18Time limit exceeded0/2301ms7728 KiB
19Time limit exceeded0/2293ms8304 KiB
20Time limit exceeded0/2293ms8928 KiB
21Time limit exceeded0/2298ms9472 KiB
22Time limit exceeded0/2298ms10248 KiB