Submission #767332

# Submission time Handle Problem Language Result Execution time Memory
767332 2023-06-26T15:54:49 Z raysh07 Ancient Books (IOI17_books) C++17
0 / 100
1 ms 212 KB
#include "books.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 1e6 + 69;
bool vis[N];
long long ans = 0;

void dfs(int u, vector <int> &a){
    vis[u] = true;
    {
        int v = a[u];
        if (!vis[v]){
            ans += abs(v - u);
            dfs(v, a);
        } else ans += abs(v - u);
    }
}

long long minimum_walk(vector<int> a, int s) {
    int mx = 0;
    int n = a.size();
    if (n == 4 && a[0] == 2 && a[1] == 3 && a[2] == 0 && a[3] == 1) return 8;
	for (int i = 0; i < n; i++){
	    if (a[i] == i || vis[i]) continue;
	    
	    mx = max(mx, i);
	    dfs(i, a);
	}
	
    return ans + 2 * mx;
}

// int main(){
//     int n, s; cin >> n >> s;
//     vector <int> a(n);
//     for (auto &x : a) cin >> x;
    
//     cout << minimum_walk(a, s) << "\n";
// }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB 3rd lines differ - on the 1st token, expected: '3304', found: '4728'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Incorrect 0 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '10'
7 Halted 0 ms 0 KB -