Submission #109505

# Submission time Handle Problem Language Result Execution time Memory
109505 2019-05-06T18:29:21 Z JustasZ Ancient Books (IOI17_books) C++14
50 / 100
317 ms 85128 KB
#include "books.h"
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 1e6 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, s, val[maxn], nxt, L[maxn], R[maxn];
ll base, add;
vector<int>p;
ll minimum_walk(vector<int>perm, int S)
{
    p = perm;
    s = S;
    n = sz(p);
    for(int i = 1; i <= n; i++)
        L[i] = mod, R[i] = -mod;
    while(n > 0 && p[n - 1] == n - 1)
        --n;
    for(int i = 0; i < n; i++)
    {
        if(val[i] == 0)
        {
            int col = ++nxt, cur = i;
            while(val[cur] == 0)
            {
                val[cur] = col;
                L[col] = min(L[col], cur);
                R[col] = max(R[col], cur);
                base += abs(p[cur] - cur);
                cur = p[cur];
            }
        }
    }
    vector<int>ends[n];
    for(int i = 1; i <= nxt; i++)
    {
        ends[L[i]].pb(+1);
        ends[R[i]].pb(-1);
    }
    int open = 0;
    for(int i = 0; i < n; i++)
    {
        for(int d : ends[i])
            open += d;
        if(i != n - 1 && open == 0)
            add++;
    }
    return base + add * 2;
}
/*int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    vector<int>perm;
    ifstream fin("in.txt");
    int n, s;
    fin >> n >> s;
    perm.resize(n);
    for(int i = 0; i < n; i++)
        fin >> perm[i];
    cout << minimum_walk(perm, s) << endl;
    return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 300 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 300 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 300 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 313 ms 54072 KB Output is correct
31 Correct 255 ms 54136 KB Output is correct
32 Correct 139 ms 26616 KB Output is correct
33 Correct 246 ms 81784 KB Output is correct
34 Correct 267 ms 81784 KB Output is correct
35 Correct 276 ms 78200 KB Output is correct
36 Correct 279 ms 66944 KB Output is correct
37 Correct 164 ms 56072 KB Output is correct
38 Correct 165 ms 54596 KB Output is correct
39 Correct 188 ms 54384 KB Output is correct
40 Correct 181 ms 54140 KB Output is correct
41 Correct 190 ms 54076 KB Output is correct
42 Correct 200 ms 54008 KB Output is correct
43 Correct 317 ms 85128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 384 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 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 300 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 384 KB Output is correct
19 Correct 2 ms 384 KB Output is correct
20 Correct 2 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 2 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 313 ms 54072 KB Output is correct
31 Correct 255 ms 54136 KB Output is correct
32 Correct 139 ms 26616 KB Output is correct
33 Correct 246 ms 81784 KB Output is correct
34 Correct 267 ms 81784 KB Output is correct
35 Correct 276 ms 78200 KB Output is correct
36 Correct 279 ms 66944 KB Output is correct
37 Correct 164 ms 56072 KB Output is correct
38 Correct 165 ms 54596 KB Output is correct
39 Correct 188 ms 54384 KB Output is correct
40 Correct 181 ms 54140 KB Output is correct
41 Correct 190 ms 54076 KB Output is correct
42 Correct 200 ms 54008 KB Output is correct
43 Correct 317 ms 85128 KB Output is correct
44 Incorrect 2 ms 384 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -