Submission #598216

# Submission time Handle Problem Language Result Execution time Memory
598216 2022-07-17T19:51:03 Z yanndev Ancient Books (IOI17_books) C++17
0 / 100
25 ms 340 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll ans = 1e18;
map<pair<vector<int>, pair<int, int>>, pair<bool, ll>> vis {};

ll recSolve(int pos, vector<int> vals, int carry, int dep) {
	if (pos >= (int)vals.size() || pos < 0)
		return 1e9;
	if (dep > 10)
		return 1e9;
	/*if (vis[{vals, {pos, carry}}].first)
		return vis[{vals, {pos, carry}}].second;*/

	ll mnAns = 1e9;
	//vis[{vals, {pos, carry}}] = {true, 1e9};

	bool ok = true;
	for (int i = 0; i < (int)vals.size(); i++)
		if (vals[i] != i)
			ok = false;
	if (ok) {
		//printf("food bruh %d %d\n", pos);
		vis[{vals, {pos, carry}}] = {true, pos};
		return pos;
	}

	mnAns = min(mnAns, 1 + recSolve(pos + 1, vals, carry, dep + 1));
	mnAns = min(mnAns, 1 + recSolve(pos - 1, vals, carry, dep + 1));

	int old = vals[pos];
	vals[pos] = carry;
	mnAns = min(mnAns, recSolve(pos, vals, old, dep + 1));
	vals[pos] = old;
	//vis[{vals, {pos, carry}}] = {true, mnAns};
	return mnAns;
}

ll minimum_walk(vector<int> p, int s) {
    int n = (int)p.size();
	return recSolve(0, p, -1, 0);
    /*vector<vector<int>> cycles {};
    vector<bool> vis (n, false);

    for (int i = 0; i < n; i++) {
        if (vis[i])
            continue;
        
        //ans += abs(i - last);
        int pos = i;
        cycles.push_back({});
        while (!vis[pos]) {
            vis[pos] = true;
            cycles.back().push_back(pos);
            //ans += abs(p[pos] - pos);
            pos = p[pos];
        }
    }

    //ans += last;
	vector<int> perm {};
	for (int i = 0; i < (int)cycles.size(); i++)
		perm.push_back(i);
	do {
		ll sub = 0;
		int lst = 0;
		for (int i = 0; i < (int)cycles.size(); i++) {
			for (auto& x: cycles[i]) {
				sub += abs(x - lst);
				lst = x;
			}
		}
		sub += lst;
		ans = min(ans, sub);
	} while (next_permutation(perm.begin(), perm.end()));
    return ans;*/
}

Compilation message

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:41:9: warning: unused variable 'n' [-Wunused-variable]
   41 |     int n = (int)p.size();
      |         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 2 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '1000000000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 2 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '1000000000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 2 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '1000000000'
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '1000000000'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 2 ms 212 KB 3rd lines differ - on the 1st token, expected: '8', found: '1000000000'
4 Halted 0 ms 0 KB -