Submission #173039

# Submission time Handle Problem Language Result Execution time Memory
173039 2020-01-03T07:38:03 Z tourist Money (IZhO17_money) C++14
0 / 100
2 ms 376 KB
#include <iostream>
#include <vector>

using namespace std;

#define ll long long
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define endl "\n"
#define METH ios::sync_with_stdio(0); cin.tie(0);
#define BEGIN cout << "BEGIN" << endl;
#define END cout << "END" << endl;

const int mod = 1e9 + 7;															/// ANOTHER HASH MOD: 228228227
const int prime = 29;																	/// ANOTHER HASH PRIME: 997
const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8);

int n;
vector < int > v, nw;

inline void purify() {
}

inline void precalc() {
}

inline void read() {
	v.push_back(0);
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int a; scanf("%d", &a);
		v.push_back(a);
	}
}

bool sorted(int l, int r) {
	for (int i = l; i < r; i++) {
		if (v[i] > v[i + 1]) {
			return false;
		}
	}

	return true;
}

int check(int l, int r) {
	if (sorted(l, r)) {
		if (nw.size() <= 1) {
			return 0;
		}

		for (int i = 1; i < nw.size(); i++) {
			if (nw[i - 1] <= v[l] && v[r] <= nw[i]) {
				return (i - 1);
			}
		}

		if (v[r] <= nw[0]) {
			return -1;
		}

		if (nw.back() <= v[l]) {
			return nw.size();
		}
	}

	return -2;
}

void put(int l, int r, int place) {
	vector < int > temp;
	for (int i = 0; i <= place && i < nw.size(); i++) {
		temp.push_back(nw[i]);
	}

	for (int i = l; i <= r; i++) {
		temp.push_back(v[i]);
	}

	for (int i = place + 1; i < nw.size(); i++) {
		temp.push_back(nw[i]);
	}

	nw = temp;
}

inline void solve() {
	int l = 1, ans = 0;
	for (int r = 1; r <= n; r++) {
		if (check(l, r) == -2 || r == n) {
			put(l, r - (r != n), check(l, r - (r != n)));
			ans++;
			if (r == n) {
				break;
			}
			l = r;
			r--;
		}
	}

	cout << ans << endl;
}

int main() {
	int t = 1;
	//scanf("%d", &t);

	//precalc();
	while (t--) {
		//purify();
		read();
		solve();
	}
}

Compilation message

money.cpp: In function 'int check(int, int)':
money.cpp:52:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 1; i < nw.size(); i++) {
                   ~~^~~~~~~~~~~
money.cpp: In function 'void put(int, int, int)':
money.cpp:72:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i <= place && i < nw.size(); i++) {
                                ~~^~~~~~~~~~~
money.cpp:80:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = place + 1; i < nw.size(); i++) {
                          ~~^~~~~~~~~~~
money.cpp: In function 'void read()':
money.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
money.cpp:31:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int a; scanf("%d", &a);
          ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -