Submission #1073660

# Submission time Handle Problem Language Result Execution time Memory
1073660 2024-08-24T17:21:56 Z guanex Ancient Books (IOI17_books) C++14
0 / 100
8 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){
        //cout << i <<" " << ans << endl;
        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(j == y.size()){
                ans += abs(x[k] - i);
                i = x[k];
                continue;
            }
            if(k == x.size() || abs(y[j] * -1 - i) < abs(x[k] - i)){
                ans += abs(y[j] * -1 - i);
                i = y[j] * -1;
            }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));
        if(p[i] < i && upper_bound(x.begin(), x.end(), i) != x.end()){
            ans += abs(i - x[upper_bound(x.begin(), x.end(), i) - x.begin()]);
            i = x[upper_bound(x.begin(), x.end(), i)-x.begin()];
        }
    }
    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){
      |                    ~~^~~~~~~~~~
books.cpp:45:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |             if(j == y.size()){
      |                ~~^~~~~~~~~~~
books.cpp:50:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |             if(k == x.size() || abs(y[j] * -1 - i) < abs(x[k] - i)){
      |                ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4414'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
6 Incorrect 0 ms 348 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -