Submission #423261

# Submission time Handle Problem Language Result Execution time Memory
423261 2021-06-10T21:00:50 Z MDario Ancient Books (IOI17_books) C++11
50 / 100
179 ms 26832 KB
#include "books.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first.first
#define S first.second
#define T second
long long minimum_walk(vector<int> p, int s){
    ll n=p.size(), r=0, x=n, y=0, z=-1;
    bool b[n];
    for(int i=0; i<n; i++){
        b[i]=0;
        if(i==p[i])b[i]=1;
    }
    vector<pair<pair<ll, ll>, vector<ll>>> v;
    vector<ll> v1;
    for(ll i=0; i<n; i++){
        if(!b[i]){
            v1.clear();
            //cout << z << " ";
            if(i>=z){
                if(z!=-1)r+=2*(i-z);
            }
            r+=p[i]-i;
            y=p[i];
            while(y!=i){
                v1.push_back(y);
                z=max(z, y);
                b[y]=1;
                r+=abs(p[y]-y);
                y=p[y];
            }
            v1.push_back(y);
            b[y]=1;
            z=max(z, y);
            v.push_back({{i, z}, v1});
        }
    }
    if(v.empty())return 0;
    unique(v.begin(), v.end());
    sort(v.begin(), v.end());
    if(s>v.back().S)return r+2*(s-v.back().S);
    if(s<=v[0].F) return r+2*(v[0].F-s);
    x=n;
    z=0;
    for(int i=0; i<v.size(); i++){
//        if(i+1==v.size()){
                //cout << v[i].F << " " << v[i].S << "\n";
            if(s>=v[i].F&&s<=v[i].S&&v[i].S>z){
                for(int t=0; t<v[i].T.size(); t++)x=min(x, abs(s-v[i].T[t]));
                z=v[i].S;
            }
//        }
//        else if(v[i+1].F!=v[i].F){
//            if(s>=v[i].F&&s<=v[i].S&&v[i].S>z){
//                for(int t=0; t<v[i].T.size(); t++)x=min(x, abs(s-v[i].T[t]));
//                z=v[i].S;
//            }
//        }
    }
    if(x==n)return r;
	return r+2*x;
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<long long int, long long int>, std::vector<long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for(int i=0; i<v.size(); i++){
      |                  ~^~~~~~~~~
books.cpp:50:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                 for(int t=0; t<v[i].T.size(); t++)x=min(x, abs(s-v[i].T[t]));
      |                              ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 179 ms 23092 KB Output is correct
31 Correct 163 ms 19884 KB Output is correct
32 Correct 116 ms 9076 KB Output is correct
33 Correct 163 ms 23792 KB Output is correct
34 Correct 163 ms 23804 KB Output is correct
35 Correct 166 ms 25584 KB Output is correct
36 Correct 157 ms 26832 KB Output is correct
37 Correct 136 ms 18244 KB Output is correct
38 Correct 132 ms 17216 KB Output is correct
39 Correct 132 ms 17084 KB Output is correct
40 Correct 135 ms 17244 KB Output is correct
41 Correct 148 ms 19532 KB Output is correct
42 Correct 155 ms 18136 KB Output is correct
43 Correct 177 ms 26572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3590'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 179 ms 23092 KB Output is correct
31 Correct 163 ms 19884 KB Output is correct
32 Correct 116 ms 9076 KB Output is correct
33 Correct 163 ms 23792 KB Output is correct
34 Correct 163 ms 23804 KB Output is correct
35 Correct 166 ms 25584 KB Output is correct
36 Correct 157 ms 26832 KB Output is correct
37 Correct 136 ms 18244 KB Output is correct
38 Correct 132 ms 17216 KB Output is correct
39 Correct 132 ms 17084 KB Output is correct
40 Correct 135 ms 17244 KB Output is correct
41 Correct 148 ms 19532 KB Output is correct
42 Correct 155 ms 18136 KB Output is correct
43 Correct 177 ms 26572 KB Output is correct
44 Incorrect 1 ms 204 KB 3rd lines differ - on the 1st token, expected: '3304', found: '3590'
45 Halted 0 ms 0 KB -