Submission #921403

# Submission time Handle Problem Language Result Execution time Memory
921403 2024-02-03T19:02:58 Z TAhmed33 Group Photo (JOI21_ho_t3) C++
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
using namespace std;
int main () {
	int n; cin >> n; int a[n + 1] = {}; for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector <int> x;
	for (int i = 1; i <= n; i++) x.push_back(i);
	int mn = 1e9;
	do {
		bool flag = 1;
		for (int i = 0; i + 1 < (int)x.size(); i++) {
			flag &= x[i] - x[i + 1] <= 1;
		}
		if (flag) {
			int pos[n + 1] = {}; for (int i = 0; i < n; i++) pos[x[i]] = i;
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				for (int j = i - 1; j >= 0; j--) {
					if (pos[a[i]] < pos[a[j]]) {
						cnt++;
					}
				}
			}
			mn = min(mn, cnt);
		}
	} while (next_permutation(x.begin(), x.end()));
	cout << mn << '\n';
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -