#include <bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> pt;
typedef pair<int, ii> iii;
typedef vector<int> vi;
#define FOR(i, l, r) for(int i = l; i <= r; ++i)
#define FORD(i, l, r) for(int i = l; i >= r; --i)
#define REP(i, r) for(int i = 0; i < int(r); ++i)
#define REPD(i, r) for(int i = int(r)-1; i >= 0; --i)
#define fi first
#define se second
#define x first
#define y second
#define sz size
#define endl '\n'
#define debug(x) cout << #x << " = " << x << endl;
#define boost ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mk make_pair
const int Nmax = 2e6 + 10;
const ll inf = 1e9;
const db _eps = 1e-15;
vi a[Nmax];
int n, s, last, startlast;
ll sum;
bool avail[Nmax];
void visit(int u) {
last = u;
avail[u] = true;
REP(i, a[u].sz()) {
int v = a[u][i];
sum += 1LL * abs(v - u);
if (avail[v] == false) {
visit(v);
}
}
}
ll minimum_walk(vi p, int s) {
s++; n = p.sz();
FOR(i, 1, n) {
a[i].push_back(p[i-1] + 1);
}
startlast = s;
FOR(i, s, n) {
if (avail[i]) continue;
sum += abs(i - startlast);
visit(i);
startlast = i;
}
FORD(i, s - 1, 1) {
if (avail[i]) continue;
sum += abs(i - startlast);
visit(i);
startlast = i;
}
return 1LL * abs(s - startlast) + sum;
}
//int main() {
/*vector <int> p;
//freopen("books.inp", "r", stdin);
cin >> n >> s;
FOR(i, 1, n) {
int x;
cin >> x;
p.push_back(x);
}*/
//cout << minimum_walk(p, s);
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47352 KB |
Output is correct |
2 |
Incorrect |
45 ms |
47464 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47352 KB |
Output is correct |
2 |
Incorrect |
45 ms |
47464 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47352 KB |
Output is correct |
2 |
Incorrect |
45 ms |
47464 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
45 ms |
47464 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '4736' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
47352 KB |
Output is correct |
2 |
Incorrect |
45 ms |
47464 KB |
3rd lines differ - on the 1st token, expected: '6', found: '8' |
3 |
Halted |
0 ms |
0 KB |
- |