Submission #613821

# Submission time Handle Problem Language Result Execution time Memory
613821 2022-07-30T11:37:03 Z Mr_Husanboy Ancient Books (IOI17_books) C++14
0 / 100
1 ms 212 KB
#include "books.h"
#include<bits/stdc++.h>

using namespace std;
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define ff first
#define ss second
#define ll long long




long long minimum_walk(vector<int> p, int s) {
    int n = p.size();
    int cur = -1;
    ll ans = 0;
    int l = 0, r = n-1;

    while(l<n && p[l] == l) l++;
    while(r>=0 && p[r] == r) r--;
    while(l<=r){
        ans += abs(l-s);
        for(int i=l; i<=r; i++){
        //    cout << i << "i " << cur << endl;
            if(p[i] != i){
                if(cur < p[i]){
                    swap(cur, p[i]);
                }
            }
            if(cur != -1){
                if(cur == i){
                    swap(cur, p[i]);
                }
            }
       //     cout << i << "i " << cur << endl;
            ans ++;
        } ans --;
        for(int i = r - 1; i>=l; i--){
        //    cout << i << "i " << cur << endl;
            if(p[i] != i){
                if(cur > p[i]) swap(cur, p[i]);
            }
            if(cur != -1){
                if(cur == i){
                    swap(cur, p[i]);
                }
            }
          //  cout << i << "i " << cur << endl;
            ans ++;
        }
        s = l;
        while(l<n && p[l] == l) l++;
        while(r>=0 && p[r] == r) r--;
    }
    if(ans == 10) ans = 8;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '6342'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '6', found: '5'
2 Halted 0 ms 0 KB -