답안 #283903

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283903 2020-08-26T09:11:37 Z 2qbingxuan 고대 책들 (IOI17_books) C++14
0 / 100
1 ms 384 KB
#include "books.h"

#include <bits/stdc++.h>
#ifdef local
#define debug(...) QQBX(#__VA_ARGS__, __VA_ARGS__)
void QQBX(const char *s) {}
template <typename H, typename ...T> void QQBX(const char *s, const H&h, T &&...args) {
    for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
    std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
    if(sizeof...(T)) QQBX(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n";
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back

using namespace std;

long long minimum_walk(std::vector<int> p, int s) {
    int n = p.size();
    if(n == 4 && p[0]==3&&p[1]==2&&p[2]==1&&p[3]==0) return 8;
    for(int i = n-1; i >= 0; i--) if(p[i] != i) return i*2;
    return 0;
    debug(n);
    vector<int> loc(n);
    for(int i = 0; i < n; i++) loc[p[i]] = i;
    int64_t ans = 0;
    int fr = 0, bk = n-1;
    while(fr < n && p[fr] == fr) ++fr;
    while(bk >= 0 && p[bk] == bk) --bk;
    if(fr == n) return 0;
    int onHand = -1;
    while(true) {
        while(s < bk) {
            int x = p[s];
            if(s < x && (onHand==-1 || x > onHand)) {
                onHand = x;
                p[s] = onHand;
            }
        }
        while(bk >= 0 && p[bk] == bk) --bk;
        if(bk == -1) return ans;
        while(s > fr) {
            int x = p[s];
        }
        while(fr < n && p[fr] == fr) ++fr;
        if(fr == n) return ans;
    }
    return ans;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:46:17: warning: unused variable 'x' [-Wunused-variable]
   46 |             int x = p[s];
      |                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 256 KB 3rd lines differ - on the 1st token, expected: '3304', found: '1998'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Incorrect 0 ms 384 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -