Submission #937322

# Submission time Handle Problem Language Result Execution time Memory
937322 2024-03-03T20:35:32 Z snpmrnhlol Ancient Books (IOI17_books) C++17
50 / 100
82 ms 22784 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e6;
const ll inf = 1e18;
ll ps[N + 1];
long long minimum_walk(std::vector<int> p, int s) {
    int n = p.size();
    ll ans = 0;
    ll mx = -inf;
    ll mn = inf;
    ll mx2 = -inf;
    ll mn2 = inf;
    bool ok = 0;
    for(ll i = 0;i < n;i++){
        ans+=abs(i - p[i]);
        if(i != p[i]){
            ok = 1;
            if(i < p[i]){
                ps[p[i]]--;
                ps[i]++;
            }
            if(i <= s){
                mx = max(mx,i);
            }
            if(i >= s){
                mn = min(mn,i);
            }
            mx2 = max(mx2,i);
            mn2 = min(mn2,i);
        }
    }
    if(ok == 0)return ans;
    ll sum = 0;
    for(int i = mn2;i < mx2;i++){
        sum+=ps[i];
        //cout<<ps[i]<<' ';
        if(sum == 0)ans+=2;
    }
    ans+=2*min(s - mx,mn - s);
	return ans;
}
/**
4 0
3 2 1 0
**/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 444 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 0 ms 444 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 444 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 0 ms 444 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 75 ms 22640 KB Output is correct
31 Correct 76 ms 22608 KB Output is correct
32 Correct 72 ms 14840 KB Output is correct
33 Correct 73 ms 22784 KB Output is correct
34 Correct 77 ms 22772 KB Output is correct
35 Correct 74 ms 22780 KB Output is correct
36 Correct 76 ms 22636 KB Output is correct
37 Correct 82 ms 22772 KB Output is correct
38 Correct 72 ms 22604 KB Output is correct
39 Correct 73 ms 22644 KB Output is correct
40 Correct 75 ms 22776 KB Output is correct
41 Correct 75 ms 22652 KB Output is correct
42 Correct 76 ms 22764 KB Output is correct
43 Correct 80 ms 22768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 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 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 444 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 600 KB Output is correct
26 Correct 0 ms 344 KB Output is correct
27 Correct 1 ms 448 KB Output is correct
28 Correct 0 ms 444 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 75 ms 22640 KB Output is correct
31 Correct 76 ms 22608 KB Output is correct
32 Correct 72 ms 14840 KB Output is correct
33 Correct 73 ms 22784 KB Output is correct
34 Correct 77 ms 22772 KB Output is correct
35 Correct 74 ms 22780 KB Output is correct
36 Correct 76 ms 22636 KB Output is correct
37 Correct 82 ms 22772 KB Output is correct
38 Correct 72 ms 22604 KB Output is correct
39 Correct 73 ms 22644 KB Output is correct
40 Correct 75 ms 22776 KB Output is correct
41 Correct 75 ms 22652 KB Output is correct
42 Correct 76 ms 22764 KB Output is correct
43 Correct 80 ms 22768 KB Output is correct
44 Incorrect 1 ms 348 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -