답안 #296724

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
296724 2020-09-10T20:28:35 Z dandrozavr 고대 책들 (IOI17_books) C++14
0 / 100
2 ms 512 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
#define F first
#define S second
#define pii pair < int , int >
#define _ <<" "<<
#define TIME 1.0 * clock() / CLOCKS_PER_SEC

vector < int > a;
int S, n;

map < vector < int > , int > mp[30];
int brute(vector < int > p, int s){
    if (mp[s].count(p)) return mp[s][p];
    mp[s][p] = 1e7;
    bool bad = 0;
    for (int i = 0; i < n; ++i)
        if (p[i] != i){
            bad = 1;
            break;
        }
    if (!bad){
        mp[s][p] = abs(s - S);
        return abs(s - S);
    }
    int pos = -1;
    bool byl[n] = {};
    for (int i = 0; i < n; ++i)
        if (p[i] != n)
            byl[p[i]] = 1;
    for (int i = 0; i < n; ++i)
        if (!byl[i]){
            pos = i;
            break;
        }
    int ans = 1e7;
//    for (int i : p) cout << i << " "; cout << endl;
    for (int i = 0; i < n; ++i){
        int dist = abs(i - s);
        ans = min(ans, dist + brute(p, i));
    }
    if (pos == -1){
        for (int i = 0; i < n; ++i){
            int dist = abs(s - i);
            int temp = p[i];
            p[i] = p[s];
            p[s] = n;
            ans = min(ans, dist + brute(p, i));
            p[s] = p[i];
            p[i] = temp;
        }
    }

    if (pos != -1){
        for (int i = 0; i < n; ++i)
            if (p[i] != n){
                int dist = abs(s - i);
                int temp = p[i];
                p[i] = pos;
                ans = min(ans, dist + brute(p, i));
                p[i] = temp;
            } else {
                p[i] = pos;
                int dist = abs(i - s);
                ans = min(ans, dist + brute(p, i));
                p[i] = n;
            }
    }
//    if (p[0] == 0 && p[1] == 2 && p[2] == 2 && p[3] == ){
//        for (int i : p) cout << i << " ";
//        cout << endl;
//        cout << s _ ans _ pos << endl << endl;
//    }
    mp[s][p] = ans;
    return ans;
}

long long minimum_walk(std::vector<int> p, int s) {
    S = s;
    a = p;
    n = p.size();
    if (n <= 4)
        return brute(p, s);
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:90:1: warning: control reaches end of non-void function [-Wreturn-type]
   90 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 500 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '6', found: '10'
9 Halted 0 ms 0 KB -