#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
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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
292 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
292 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Execution timed out |
2108 ms |
826620 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
292 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Execution timed out |
2108 ms |
826620 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2152 ms |
849604 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
292 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Execution timed out |
2108 ms |
826620 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |