Submission #612369

# Submission time Handle Problem Language Result Execution time Memory
612369 2022-07-29T13:37:04 Z 8e7 Giraffes (JOI22_giraffes) C++17
32 / 100
7000 ms 304 KB
//Challenge: Accepted
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define double long double
#define maxn 2005
#define pii pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
const ll inf = 1LL<<50;

int p[maxn];
int n;

int ans = 10000;
void build(int se, vector<int> v, int cnt) {
	if (v.size() == n) {
		ans = min(ans, cnt);
		return;
	}
	for (int i = 0;i < n;i++) {
		if (!((se>>i) & 1)) {
			int to = se + (1<<i);
			int mi = i, ma = i;
			bool good = 1;
			for (int j = (int)v.size() - 1;j >= 0;j--) {
				if (mi != i && ma != i && mi < v[j] && v[j] < ma) {
					good = 0;
					break;
				}
				mi = min(mi, v[j]);
				ma = max(ma, v[j]);
			}
			if (good) {
				vector<int> tv = v;
				tv.push_back(i);
				int tc = cnt;
				if (p[v.size()] != i) tc++; 
				build(to, tv, tc);
			}
		}
	}
}

int main() {
	io
	cin >> n;
	for (int i = 0;i < n;i++) cin >> p[i], p[i]--;
	vector<int> ini;
	build(0, ini, 0);
	cout << ans << "\n";
}

Compilation message

giraffes.cpp: In function 'void build(int, std::vector<int>, int)':
giraffes.cpp:30:15: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   30 |  if (v.size() == 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 12 ms 212 KB Output is correct
13 Correct 59 ms 300 KB Output is correct
14 Correct 256 ms 300 KB Output is correct
15 Correct 1916 ms 304 KB Output is correct
16 Correct 1191 ms 296 KB Output is correct
17 Correct 6630 ms 304 KB Output is correct
18 Correct 6896 ms 300 KB Output is correct
19 Correct 5584 ms 300 KB Output is correct
20 Correct 5686 ms 296 KB Output is correct
# 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 12 ms 212 KB Output is correct
13 Correct 59 ms 300 KB Output is correct
14 Correct 256 ms 300 KB Output is correct
15 Correct 1916 ms 304 KB Output is correct
16 Correct 1191 ms 296 KB Output is correct
17 Correct 6630 ms 304 KB Output is correct
18 Correct 6896 ms 300 KB Output is correct
19 Correct 5584 ms 300 KB Output is correct
20 Correct 5686 ms 296 KB Output is correct
21 Execution timed out 7092 ms 212 KB Time limit exceeded
22 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 12 ms 212 KB Output is correct
13 Correct 59 ms 300 KB Output is correct
14 Correct 256 ms 300 KB Output is correct
15 Correct 1916 ms 304 KB Output is correct
16 Correct 1191 ms 296 KB Output is correct
17 Correct 6630 ms 304 KB Output is correct
18 Correct 6896 ms 300 KB Output is correct
19 Correct 5584 ms 300 KB Output is correct
20 Correct 5686 ms 296 KB Output is correct
21 Execution timed out 7092 ms 212 KB Time limit exceeded
22 Halted 0 ms 0 KB -