#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});
while(!q.empty()){
int kur = q.front().first.first;
int kas = q.front().first.second;
vector<int> ms = q.front().second;
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;
swap(vec[kur], kas);
if(!dist.count({{kur, kas}, vec}) || dist[{{kur, kas}, vec}] > dist[{{kur, kas}, ms}] ){
dist[{{kur, kas}, vec}] = dist[{{kur, kas}, 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}}];
}
Compilation message
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:19:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if(kur + 1 < p.size() && !dist.count({{kur+1, kas}, ms}) || dist[{{kur+1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
| ~~~~~~~~^~~~~~~~~~
books.cpp:19:25: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
19 | if(kur + 1 < p.size() && !dist.count({{kur+1, kas}, ms}) || dist[{{kur+1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
books.cpp:24:19: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
24 | if(kur - 1 >= 0 && !dist.count({{kur-1, kas}, ms}) || dist[{{kur-1, kas}, ms}] > dist[{{kur, kas}, ms}] + 1){
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
books.cpp:35:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | 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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
3rd lines differ - on the 1st token, expected: '6', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
3rd lines differ - on the 1st token, expected: '6', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
3rd lines differ - on the 1st token, expected: '6', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2123 ms |
941476 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
332 KB |
3rd lines differ - on the 1st token, expected: '6', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |