답안 #1073644

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1073644 2024-08-24T16:56:21 Z vjudge1 고대 책들 (IOI17_books) C++17
0 / 100
6 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) && j != x.size()){
                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){
      |                    ~~^~~~~~~~~~
books.cpp:44:51: 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]
   44 |             if(abs(y[j] - i) < abs(x[k] - i) && j != x.size()){
      |                                                 ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 0 ms 344 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 -
# 결과 실행 시간 메모리 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 0 ms 344 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 -
# 결과 실행 시간 메모리 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 0 ms 344 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 -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4738'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 0 ms 344 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 -