Submission #423619

# Submission time Handle Problem Language Result Execution time Memory
423619 2021-06-11T10:31:56 Z arayi Ancient Books (IOI17_books) C++17
0 / 100
1 ms 204 KB
#include "books.h"
#include <bits/stdc++.h>
#define lli long long
#define ad push_back
#define fr first
#define sc second
#define MP make_pair
using namespace std;

const int N = 1e6 + 30;

int i1 = 1, n;
int col[N], a[N];
lli ans;
int dfs(int v)
{
    col[v] = i1;
    if(!col[a[v]]) return max(v, dfs(a[v]));
    return v;
}
long long minimum_walk(vector<int> p, int s)
{
	n = p.size();
	for(int i = 0; i < n; i++) a[i] = p[i], ans += abs(a[i] - i);
	int nx = -1;
	for(int i = 0; i < n; i++)
    {
        if(a[i] == i) continue;
        if(!col[i])
        {
            if(nx >= 0 && i > nx) ans += 2*(i - nx), i1++;
            nx = max(nx, dfs(i));
        }
    }
    int dz = -1, aj = -1;
    for(int i = s; i < n; i++)
    {
        if(col[i])
        {
            aj = i;
            break;
        }
    }
    for(int i = s; i >= 0; i--)
    {
        if(col[i])
        {
            dz = i;
            break;
        }
    }
    if(dz == -1 && aj == -1) return 1;
    else if(dz == -1) return ans += 2*abs(aj - s), 2;
    else if(aj == -1) return ans += 2*abs(s - dz), 3;
    else ans += 2*min(aj - s, s - dz);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '2'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '6', found: '2'
2 Halted 0 ms 0 KB -