#include <bits/stdc++.h>
#include "books.h"
using namespace std;
using ll = long long;
constexpr ll INF = 1000000000000000000LL;
ll n, m, q, k, x, y, a, b, c;
map< pair< vector<int>, pair<int, int> >, ll > mp;
vector<int> perfect;
long long minimum_walk(vector<int> p, int s) {
ll num = 0;
bool fl = 1;
for (int i = 0; i < p.size(); i++) {
num += abs(i - p[i]);
if (i != p[i]) {
fl = 0;
}
if (fl) {
num += 2;
}
}
return num;
// for (int i = 0; i < p.size(); i++) {
// perfect.push_back(i);
// }
// deque< pair< vector<int>, pair<int, int> > > q;
// q.push_back({p, {s, -1}});
// mp[{p, {s, -1}}] = 0;
// while (!q.empty()) {
// auto [p, p2] = q[0];
// auto [s, carry] = p2;
// q.pop_front();
// // for (auto i : p) {
// // cout << i << ' ';
// // }
// // cout << endl;
// // cout << s << ' ' << carry << endl;
// if (p == perfect && s == 0 && carry == -1) {
// return mp[{p, {s, carry}}];
// }
// ll d = mp[{p, {s, carry}}];
// swap(carry, p[s]);
// if (!mp.count({p, {s, carry}})) {
// q.push_front({p, {s, carry}});
// mp[{p, {s, carry}}] = d;
// }
// swap(carry, p[s]);
// if (s > 0 && !mp.count({p, {s - 1, carry}})) {
// q.push_back({p, {s - 1, carry}});
// mp[{p, {s - 1, carry}}] = d + 1;
// }
// if (s < p.size() - 1 && !mp.count({p, {s + 1, carry}})) {
// q.push_back({p, {s + 1, carry}});
// mp[{p, {s + 1, carry}}] = d + 1;
// }
// }
}
Compilation message
books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:17:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for (int i = 0; i < p.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '2744' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
3rd lines differ - on the 1st token, expected: '0', found: '8' |
10 |
Halted |
0 ms |
0 KB |
- |