Submission #1073639

# Submission time Handle Problem Language Result Execution time Memory
1073639 2024-08-24T16:52:04 Z guanex Ancient Books (IOI17_books) C++14
0 / 100
2000 ms 348 KB
#include "books.h"
#include<bits/stdc++.h>

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef pair<char, int> ci;
typedef pair<string, int> si;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
#define pb push_back
#define fi first
#define se second
#define whole(v) v.begin(), v.end()
#define rwhole(v) v.rbegin(), v.rend()
#define inf INT_MAX/2
#define fro front

long long minimum_walk(std::vector<int> p, int s) {
    vector<ll> x;
    vector<ll> y;
    for(int i = 0; i < p.size(); ++i){
        if(p[i] == i){
            x.pb(-1);
            y.pb(-inf);
        }else{
            x.pb(i);
            y.pb(-i);
        }
    }
    sort(whole(x));
    sort(whole(y));
    long long ans = 0;
    int i = s;
    while(x[x.size()-1] != -1){
        ll k = lower_bound(x.begin(), x.end(), i) - x.begin();
        if(x[k] != i){
            ll j = lower_bound(y.begin(), y.end(), -i) - y.begin();
            if(abs(y[j] - i) < abs(x[k] - i)){
                ans += abs(y[j] - i);
                i = +y[j];
            }else{
                ans += abs(x[k] - i);
                i = x[k];
            }
        }
        ans += abs(p[i] - i);
        x[lower_bound(x.begin(), x.end(), i) - x.begin()] = -1;
        y[lower_bound(y.begin(), y.end(), -i) - y.begin()] = -inf;
        i = p[i];
        sort(whole(y));
        sort(whole(x));
    }
    ans += abs(i - s);
	return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < p.size(); ++i){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Execution timed out 2098 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Execution timed out 2098 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Execution timed out 2098 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4738'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Execution timed out 2098 ms 348 KB Time limit exceeded
7 Halted 0 ms 0 KB -