Submission #355525

# Submission time Handle Problem Language Result Execution time Memory
355525 2021-01-22T16:30:25 Z beksultan04 Ancient Books (IOI17_books) C++14
0 / 100
1 ms 364 KB
#include "books.h"
#ifndef EVAL
#include "grader.cpp"
#endif // EVAL
#include <bits/stdc++.h>
using namespace std;
#define lol long long
#define pii pair<int,int>
#define pll pair<lol,lol>
#define OK puts("OK");
#define NO puts("NO");
#define YES puts("YES");
#define fr first
#define sc second
#define ret return
#define scanl(a) scanf("%lld",&a);
#define scanll(a,b) scanf("%lld %lld",&a, &b);
#define scanlll(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define scan1(a) scanf("%d",&a);
#define scan2(a,b) scanf("%d %d",&a, &b);
#define scan3(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define allr(s) s.rbegin(),s.rend()
#define pb push_back
#define sz(v) (int)v.size()
#define endi puts("");
#define eps 1e-12
int vis[1000001],q[1000001],ans,n;
map<vector<int>,int> mp;

lol minimum_walk(vector<int> p, int s) {
    n = p.size();
    int i;
    lol ans=0;
    vector <pll> v;
    for (i=0;i<n;++i){
        int x = p[i],l=i,r=i;
        lol c=0;
        while (vis[x] == 0){
            vis[x] = 1;
            l = min(l,x);
            r = max(x,r);
            c += abs(p[x]-x);
            x = p[x];
        }
        ans += c+(p[i]-i);
        v.pb({l,r});
    }
    v.pb({s,s});
    sort(all(v));
    for (i=1;i<v.size();++i){
        ans += 2*(max(0ll,v[i].fr-v[i-1].sc));
        v[i].sc = max(v[i].sc,v[i-1].sc);
    }
    ret ans;
}






/*
4 0
0 2 3 1
*/




Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:51:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |     for (i=1;i<v.size();++i){
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 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 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 0 ms 364 KB Output is correct
5 Incorrect 1 ms 364 KB 3rd lines differ - on the 1st token, expected: '4', found: '6'
6 Halted 0 ms 0 KB -