Submission #1080719

# Submission time Handle Problem Language Result Execution time Memory
1080719 2024-08-29T13:09:09 Z andrei_iorgulescu Ancient Books (IOI17_books) C++14
0 / 100
1 ms 1372 KB
#include <bits/stdc++.h>
#include "books.h"
#warning That's not FB, that's my FB

using namespace std;

using ll = long long;

int n, s;
int p[1000005], pos[1000005];
vector<vector<int>> cyc;
vector<int> cur;
bool viz[1000005];

void dfs(int nod)
{
    viz[nod] = true;
    cur.push_back(nod);
    if (!viz[p[nod]])
        dfs(p[nod]);
}

ll minimum_walk(vector<int> PERM, int STR)
{
    cyc.clear();
    memset(viz,0,sizeof(viz));
    n = PERM.size();
    for (int i = 1; i <= n; i++)
        p[i] = PERM[i - 1] + 1, pos[p[i]] = i;
    s = STR;
    for (int i = 1; i <= n; i++)
    {
        if (!viz[i])
        {
            cur.clear();
            dfs(i);
            cyc.push_back(cur);
        }
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++)
        ans += abs(i - p[i]);
    int adg = 0;
    int mxm = 0;
    int ult = 1;
    for (int i = 1; i <= n; i++)
    {
        if (mxm == i - 1 and i != 1)
            adg += 2;
        mxm = max(mxm, p[i]);
    }
    ans += adg;
    int pzz = n;
    while (pzz != 0 and p[pzz] == pzz)
        ans -= 2, pzz--;
    return ans;
}

Compilation message

books.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
    3 | #warning That's not FB, that's my FB
      |  ^~~~~~~
books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:45:9: warning: unused variable 'ult' [-Wunused-variable]
   45 |     int ult = 1;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Incorrect 1 ms 1372 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Incorrect 1 ms 1372 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Incorrect 1 ms 1372 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1368 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 1368 KB Output is correct
2 Correct 1 ms 1372 KB Output is correct
3 Correct 1 ms 1372 KB Output is correct
4 Correct 1 ms 1372 KB Output is correct
5 Correct 1 ms 1372 KB Output is correct
6 Correct 1 ms 1372 KB Output is correct
7 Correct 1 ms 1372 KB Output is correct
8 Correct 1 ms 1372 KB Output is correct
9 Incorrect 1 ms 1372 KB 3rd lines differ - on the 1st token, expected: '0', found: '-2'
10 Halted 0 ms 0 KB -