답안 #1103517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1103517 2024-10-21T06:23:29 Z stdfloat Money (IZhO17_money) C++17
0 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

#define ff	first
#define ss	second
#define pii	pair<int, int>

#define sz(v)	(int)(v).size()
#define all(v)	(v).begin(), (v).end()

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);

	int n;
	cin >> n;

	vector<int> a(n);
	for (auto &i : a) {
		cin >> i; i--;
	}

	int mn = INT_MAX;
	for (int mk = 0; mk < 1 << n - 2; mk++) {
		// if (mk != 10) continue;

		vector<pii> v;
		bool tr = true;
		int pre = -1, cnt = 0;
		for (int i = 0; i < n && tr; i++) {
			// cout << i << ' ' << ((mk >> i) & 1) << '\n';
			if (i != n - 1 && !((mk >> i) & 1)) continue;

			// cout << pre << ' ' << i << '\n';
			for (int j = pre + 1; j < i && tr; j++) {
				tr = (a[j] < a[j + 1]);
				v.push_back({a[j], a[j + 1]});
			}

			cnt++; pre = i;
		}

		// if (mk == 10) {
		// 	cout << tr << '\n';
		// 	for (auto i : v)
		// 		cout << i.ff + 1 << ' ' << i.ss + 1 << '\n';
		// 	cout << '\n';
		// 	continue;
		// }

		if (!tr) continue;
	
		sort(all(v));
		set<int> s = {INT_MAX};
		for (auto i : v) {
			// cout << i.ff << ' ' << *s.lower_bound(i.ff) << ' ' << i.ss << '\n';
			if (*s.lower_bound(i.ff) <= i.ss) {
				tr = false; break;
			}

			s.insert(i.ss);
		}

		if (tr) mn = min(mn, cnt);
	}

	cout << mn;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:23:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   23 |  for (int mk = 0; mk < 1 << n - 2; mk++) {
      |                             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -