답안 #297975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
297975 2020-09-12T08:54:36 Z Autoratch 고대 책들 (IOI17_books) C++14
0 / 100
976 ms 1144 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,tuple<int,int,int> > 

const int N = 2000;

int n;
map<int,vector<int> > ma;
map<vector<int>,int> mb;
int res[N][5][5];
priority_queue<pii,vector<pii>,greater<pii> > q;
bool visited[N][5][5];

long long minimum_walk(std::vector<int> p, int s) 
{
    n = p.size();
    vector<int> v;
    for(int i = 0;i < n;i++) v.push_back(i);
    int cnt = 0;
    if(n==4) for(int i = 0;i <= 4;i++) for(int j = 0;j <= 4;j++) for(int k = 0;k <= 4;k++) for(int l = 0;l <= 4;l++) 
    {
        vector<int> v = {i,j,k,l};
        ma[cnt] = v;
        mb[v] = cnt;
        cnt++;
    }
    else if(n==3) for(int i = 0;i <= 4;i++) for(int j = 0;j <= 4;j++) for(int k = 0;k <= 4;k++)
    {
        vector<int> v = {i,j,k};
        ma[cnt] = v;
        mb[v] = cnt;
        cnt++;
 
    }
    else if(n==2) for(int i = 0;i <= 4;i++) for(int j = 0;j <= 4;j++)
    {
        vector<int> v = {i,j};
        ma[cnt] = v;
        mb[v] = cnt;
        cnt++;
    }
    else for(int i = 0;i <= 4;i++)
    {
        vector<int> v = {i};
        ma[cnt] = v;
        mb[v] = cnt;
        cnt++;
    }   
    for(int i = 0;i < N;i++) for(int j = 0;j <= n;j++) for(int k = 0;k <= n;k++) res[i][j][k] = INT_MAX;
    res[mb[p]][s][4] = 0;
    q.push({0,{mb[p],s,4}});
    while(!q.empty())
    {
        auto [per,id,hn] = q.top().second;
        q.pop();
        if(visited[per][id][hn]) continue;
        visited[per][id][hn] = true;
        vector<int> now = ma[per];
        for(int i = 0;i < 4;i++) if(res[per][id][hn]+abs(id-i)<res[per][i][hn])
        {
            res[per][i][hn] = res[per][id][hn]+abs(id-i);
            q.push({res[per][i][hn],{per,i,hn}});
        }
        vector<int> nx = now;
        int hnd = nx[id];
        nx[id] = hn;
        if(res[per][id][hn]<res[mb[nx]][id][hnd])
        {
            res[mb[nx]][id][hnd] = res[per][id][hn];
            q.push({res[mb[nx]][id][hnd],{mb[nx],id,hnd}});
        }
    }
    vector<int> ans;
    for(int i = 0;i < n;i++) ans.push_back(i);
    return res[mb[ans]][0][4];
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:55:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   55 |         auto [per,id,hn] = q.top().second;
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '4', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '4', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '4', found: '0'
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 976 ms 1144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Incorrect 1 ms 512 KB 3rd lines differ - on the 1st token, expected: '4', found: '0'
5 Halted 0 ms 0 KB -