//Power Of Ninja Go
#include <bits/stdc++.h>
#ifdef atom
#include "grader.cpp"
#else
#include "books.h"
#endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector< ii > vii;
#define X first
#define Y second
#define pb push_back
int n;
const int maxn = 1e6+5;
vector<int> p;
int a[maxn], b[maxn];
bool vis[maxn];
int cnt = 0;
void dfs(int u)
{
if(vis[u]) return;
vis[u] = true;
a[cnt] = min(u, a[cnt]);
b[cnt] = max(u, b[cnt]);
dfs(p[u]);
}
long long minimum_walk(std::vector<int> P, int s)
{
p = P;
n = P.size();
for(int i = 0; i< n; i++)
{
if(vis[i]) continue;
dfs(i); cnt++;
}
int ed = 0;
ll res = 0;
for(int i = 0; i< cnt; i++)
{
if(ed< a[i])
{
res += 2*(a[i]-ed);
ed = a[i];
}
res += 2*(b[i]-a[i]);
}
return res;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
548 KB |
3rd lines differ - on the 1st token, expected: '3304', found: '725892' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
3rd lines differ - on the 1st token, expected: '6', found: '10' |
3 |
Halted |
0 ms |
0 KB |
- |