Submission #1010717

# Submission time Handle Problem Language Result Execution time Memory
1010717 2024-06-29T09:56:47 Z lrancic Crazy old lady (IZhO13_crazy) C++17
0 / 100
0 ms 344 KB
#include <iostream>
#include <vector>

bool check_arr(int n, std::vector<int> &line, int crazy) {
	if (crazy == line.back()) return false;
	for (int i = n-1; i >= 0; i--) {
		if (line[i] == crazy) return true;
		if (i+1 == line[i]) continue;
		return false;
	}
	return false;
}

int solve(int n, std::vector<int> &line) {
	int valid = 0;
	for (int i = 1; i <= n; i++) {
		if (check_arr(n, line, i)) {
			if (!valid) { valid = i; continue; }
			return 0;
		}
	}

	return valid;
}

int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
	int _; std::cin >> _; while (_--) {
		int n; std::cin >> n; std::vector<int> line(n); for (int i = 0; i < n; i++) std::cin >> line[i];
		std::cout << solve(n, line) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -