답안 #68731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68731 2018-08-18T09:51:54 Z Talant 고대 책들 (IOI17_books) C++17
0 / 100
2 ms 364 KB
#include "books.h"
//#include "grader.cpp"

#include <bits/stdc++.h>

#define sc second
#define fr first
#define mk make_pair
#define pb push_back

using namespace std;

const int N = (1e6 + 5);
const int inf = (1e9 + 7);

int f;
int cur = -1,id;
int u[N];
int ans;

long long minimum_walk(vector<int> p, int s) {
      for (int i = 0; i < p.size(); i ++)
            u[p[i]] = i;

      for (int i = p.size() - 1; i >= 0; i --) {
            if (p[i] != i) {
                  if (cur == i) {
                        ans += abs(i - id);
                        swap(cur,p[i]);
                        id = i;
                  }
                  else {
                        ans += abs(u[i] - id) + abs(u[i] - i);
                        if (cur != -1)
                              swap(p[u[i]],cur);

                        cur = i;
                        swap(cur,p[i]);
                        id = i;
                  }
            }
      }
      return (ans + id);
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:22:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (int i = 0; i < p.size(); i ++)
                       ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 364 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4814'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 248 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
2 Halted 0 ms 0 KB -