Submission #354900

# Submission time Handle Problem Language Result Execution time Memory
354900 2021-01-22T07:09:06 Z beksultan04 Ancient Books (IOI17_books) C++14
0 / 100
2000 ms 78608 KB
#include "books.h"
#ifndef EVAL
#include "grader.cpp"
#endif // EVAL
#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define pii pair<int,int>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
int pos[1000001],q[1000001],ans,n;
map<vector<int>,int> mp;
bool is(){
    int i;
    for (i=0;i<n;++i)
        if (q[i] != i)ret 0;
    ret 1;
}

int rec(int j,int x,int sum,int cnt=0){
    if (is())ret sum+(max(j,0));
    if (cnt > n*n+2)ret 1e9+7;
    int ans = 1e9+7,i;
    for (i=0;i<n;++i){
        if (i != j){
            swap(x,q[i]);
            ans = min(ans,rec(i,x,sum+abs(j-i),cnt+1));
            swap(x,q[i]);
        }
    }
    ret ans;
}

lol minimum_walk(vector<int> p, int s) {
    n = p.size();
    int i;
    for (i=0;i<n;++i)
        q[i] = p[i];
    int ans = rec(-1,-1,0)-1;
    if (ans < 0)ans =0;
    ret ans;
}






/*
4 0
0 2 3 1
*/




# Verdict Execution time Memory Grader output
1 Execution timed out 2098 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2098 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2098 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2098 ms 78608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2098 ms 364 KB Time limit exceeded
2 Halted 0 ms 0 KB -