Submission #593976

# Submission time Handle Problem Language Result Execution time Memory
593976 2022-07-11T18:49:58 Z AlperenT Ancient Books (IOI17_books) C++17
12 / 100
2000 ms 1048576 KB
#include <bits/stdc++.h>
#include "books.h"

using namespace std;

const int N = 7, F = 5040, INF = 1e9 + 5;

struct Item{
    vector<int> arr;

    int indx, hold;

    bool operator < (const Item &sc) const{
        if(arr == sc.arr){
            if(indx == sc.indx) return hold < sc.hold;
            else return indx < sc.indx;
        }
        else return arr < sc.arr;
    }
};

map<Item, int> dist;

long long minimum_walk(vector<int> p, int s){
    int n = p.size();

    vector<int> v(n);
    iota(v.begin(), v.end(), 0);

    dist[{p, s, -1}] = 0;

    priority_queue<pair<int, Item>> pq;

    pq.push({0, {p, s, -1}});

    while(!pq.empty()){
        auto v = pq.top().second; pq.pop();

        if(v.indx - 1 >= 0){
            Item nxt = {v.arr, v.indx - 1, v.hold};

            if(dist.find(nxt) == dist.end() || dist[v] + 1 < dist[nxt]){
                dist[nxt] = dist[v] + 1;
                pq.push({-dist[nxt], nxt});
            }
        }

        if(v.indx + 1 < n){
            Item nxt = {v.arr, v.indx + 1, v.hold};

            if(dist.find(nxt) == dist.end() || dist[v] + 1 < dist[nxt]){
                dist[nxt] = dist[v] + 1;
                pq.push({-dist[nxt], nxt});
            }
        }

        if(v.hold == -1){
            if(v.arr[v.indx] != -1){
                Item nxt = {v.arr, v.indx, v.arr[v.indx]};

                nxt.arr[v.indx] = -1;

                if(dist.find(nxt) == dist.end() || dist[v] < dist[nxt]){
                    dist[nxt] = dist[v];
                    pq.push({-dist[nxt], nxt});
                }
            }
        }

        if(v.hold != -1){
            Item nxt = v;

            swap(nxt.arr[nxt.indx], nxt.hold);

            if(dist.find(nxt) == dist.end() || dist[v] < dist[nxt]){
                dist[nxt] = dist[v];
                pq.push({-dist[nxt], nxt});
            }
        }
    }

    vector<int> sorted(n);

    iota(sorted.begin(), sorted.end(), 0);

    return dist[{sorted, s, -1}];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 216 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 216 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Runtime error 1435 ms 1048576 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 216 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Runtime error 1435 ms 1048576 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2078 ms 332228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 284 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 296 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 216 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Runtime error 1435 ms 1048576 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -