Submission #506623

# Submission time Handle Problem Language Result Execution time Memory
506623 2022-01-12T06:05:55 Z abc864197532 Money (IZhO17_money) C++17
0 / 100
1500 ms 288 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l)
		cout << *l << " \n"[l + 1 == r];
}
#define test(x...) abc("[" + string(#x) + "]", x);
const int N = 200000;

int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector <int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i], --a[i];
	}
	vector <int> now(n);
	iota(all(now), 0);
	auto chk = [&](int from, int to) {
		for (int i = 0; i + to - from <= now.size(); ++i) {
			bool is = true;
			for (int j = 0; j < to - from; ++j)
				is &= now[i + j] == a[from + j];
			if (is)
				return i;
		}
		return -1;
	};
	int ans = 0;
	int end = n;
	while (end) {
		for (int i = 0; i < end; ++i) {
			int from = chk(i, end);
			if (from != -1) {
				now.erase(now.begin() + from, now.begin() + from + end - i);
				++ans;
				end = i;
				break;
			}
		}
	}
	cout << ans << endl;
}

/*
6
3 6 4 5 1 2
*/

Compilation message

money.cpp: In lambda function:
money.cpp:35:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for (int i = 0; i + to - from <= now.size(); ++i) {
      |                   ~~~~~~~~~~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Execution timed out 1564 ms 204 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Execution timed out 1564 ms 204 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Execution timed out 1564 ms 204 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 288 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Execution timed out 1564 ms 204 KB Time limit exceeded
5 Halted 0 ms 0 KB -