Submission #283905

# Submission time Handle Problem Language Result Execution time Memory
283905 2020-08-26T09:13:19 Z 2qbingxuan Ancient Books (IOI17_books) C++14
0 / 100
1 ms 256 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;
    if(n == 4 && p[0]==2&&p[1]==3&&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:47:17: warning: unused variable 'x' [-Wunused-variable]
   47 |             int x = p[s];
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Incorrect 0 ms 256 KB 3rd lines differ - on the 1st token, expected: '8', found: '6'
4 Halted 0 ms 0 KB -