Submission #532583

# Submission time Handle Problem Language Result Execution time Memory
532583 2022-03-03T09:00:01 Z stefantaga Ancient Books (IOI17_books) C++14
0 / 100
1 ms 280 KB
#include <cstdio>
#include <vector>
#include <cassert>
#include <bits/stdc++.h>
#include "books.h"
int n,v[1000005],pozitii[1000005];
using namespace std;
long long minimum_walk(std::vector<int> p, int s)
{
    n=p.size();
    int i;
    for (i=1; i<=n; i++)
    {
        v[i]=p[i-1]+1;
    }
    int sum=0,acum=s+1,nr=0;
    for (i=1; i<=n; i++)
    {
        if (v[i]!=i)
        {
            nr++;
        }
    }
    if (nr<4)
    {
        for (i=1; i<=n; i++)
        {
            if (v[i]!=i)
            {
                int ceam;
                sum=sum+abs(acum-i);
                acum=i;
                ceam=v[i];
                v[i]=0;
                while (v[ceam]&&ceam!=acum)
                {
                    sum=sum+abs(acum-ceam);
                    acum=ceam;
                    swap(v[ceam],ceam);
                }

                sum=sum+abs(acum-ceam);
                acum=ceam;
                v[ceam]=ceam;
            }
        }
        sum=sum+abs(acum-(s+1));
        return sum;
    }
    else
    {
        pozitii[1]=1;
        pozitii[2]=2;
        pozitii[3]=v[1];
        pozitii[4]=v[2];
        sort (pozitii+1,pozitii+5);
        return pozitii[2]-pozitii[1]+(pozitii[3]-pozitii[2])*3+pozitii[4]-pozitii[3]+pozitii[4]-pozitii[1];
    }
    return 0;
}
#ifdef HOME
int main()
{
    ifstream cin("date.in");
    ofstream cout("date.out");
    int n, s;
    cin>>n>>s;

    vector<int> p((unsigned) n);
    for(int i = 0; i < n; i++)
    {
        cin>>p[i];
    }
    long long res = minimum_walk(p, s);
    cout<<res;

    return 0;
}
#endif // HOME
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 0 ms 280 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 0 ms 280 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 0 ms 280 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
8 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: '4'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Incorrect 0 ms 280 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
8 Halted 0 ms 0 KB -