This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
long long minimum_walk(vector<int> p, int s) {
vector<int> eil;
int n = p.size();
int pw = 1;
for(int i = 0; i < 10; i++) pw *= 3;
vector<int> mas(p.size());
int ans = 1e9;
map<pair<pair<int,int>, vector<int> > , int> dist;
queue<pair<pair<int, int>, vector<int> > > q;
q.push({{0, -1}, p});
dist[{{0,-1}, p}] = 0;
while(!q.empty()){
int kur = q.front().first.first;
int kas = q.front().first.second;
vector<int> ms = q.front().second;
//cout << "kur: " << kur << ", kas: " << kas << ", ms: "; for(auto x : ms) cout << x<< " "; cout << ", dist : " << dist[{{kur, kas}, ms}] << endl;
q.pop();
if(kur + 1 < p.size() && !dist.count({{kur+1, kas}, ms}) || dist[{{kur+1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
dist[{{kur+1, kas}, ms}] = 1 + dist[{{kur, kas}, ms}];
q.push({{kur+1, kas}, ms});
}
if(kur - 1 >= 0 && !dist.count({{kur-1, kas}, ms}) || dist[{{kur-1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
dist[{{kur-1, kas}, ms}] = dist[{{kur, kas}, ms}] + 1;
q.push({{kur-1, kas}, ms});
}
vector<int>vec = ms;
int kss = kas;
swap(vec[kur], kas);
if(!dist.count({{kur, kas}, vec}) || dist[{{kur, kas}, vec}] > dist[{{kur, kss}, ms}] ){
dist[{{kur, kas}, vec}] = dist[{{kur, kss}, ms}];
q.push({{kur, kas}, vec});
}
}
vector<int> goal; for(int i = 0; i < p.size(); i++) goal.push_back(i);
return dist[{{0, -1}, {goal}}];
}// A A A A
Compilation message (stderr)
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:21:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(kur + 1 < p.size() && !dist.count({{kur+1, kas}, ms}) || dist[{{kur+1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
| ~~~~~~~~^~~~~~~~~~
books.cpp:21:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
21 | if(kur + 1 < p.size() && !dist.count({{kur+1, kas}, ms}) || dist[{{kur+1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
books.cpp:26:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
26 | if(kur - 1 >= 0 && !dist.count({{kur-1, kas}, ms}) || dist[{{kur-1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
books.cpp:39:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | vector<int> goal; for(int i = 0; i < p.size(); i++) goal.push_back(i);
| ~~^~~~~~~~~~
books.cpp:6:6: warning: unused variable 'n' [-Wunused-variable]
6 | int n = p.size();
| ^
books.cpp:10:6: warning: unused variable 'ans' [-Wunused-variable]
10 | int ans = 1e9;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |