Submission #1050032

# Submission time Handle Problem Language Result Execution time Memory
1050032 2024-08-09T06:56:58 Z MercubytheFirst Comparing Plants (IOI20_plants) C++17
0 / 100
19 ms 5364 KB
#include <bits/stdc++.h>
#include "plants.h"
template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p);
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s);
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s);
using namespace std;

int n;
vector<int> group, big;
void init(int k, std::vector<int> r) {
	big = r;
	n = r.size();
	group.assign(n, -1);
	vector<bool> used(n);
	for(int round = 0; round < n; ++round) {
		int nonz = 0;
		vector<int> did;
		for(int idx = 0; idx < 2*n; ++idx) {
			int i = idx%n;
			if(used[i]) {
				// assert(big[i] == 0);
				nonz++;
				continue;
			}
			if(big[i] > 0) {
				nonz++;
			}
			else if(big[i] == 0) {
				if(nonz >= k - 1) {
					used[i] = true;
					did.push_back(i);
					group[i] = n - round;
				}
				nonz = 0;
			}
			else assert(false);
		}
		if(did.empty()) {
			assert(count(used.begin(), used.end(), true) == n);
			break;
		}
		for(int x : did) {
			int start = (((x - k + 1) % n + n) % n);

			for(int i = start; i != x; i = (i + 1) % n) {
				if(used[i]) {
					continue;
				}
				assert(big[i] > 0);
				--big[i];
			}
		}
	}
	assert(count(group.begin(), group.end(), -1) == 0);
	// cout << group << endl;
}

int compare_plants(int x, int y) {
	assert(group[x] != -1 and group[y] != -1);
	if(group[x] > group[y]) {
		return 1;
	}
	else if(group[x] < group[y]) {
		return -1;
	}
	else {
		assert(group[x] == group[y]);
		return 0;
	}
}



template<typename T, size_t N>
std::ostream& operator<<(std::ostream& os, const std::array<T, N>& a) {
  os << "[";
  for(size_t i = 0; i + 1 < N; ++i) {
    os << a[i] << ", ";
  }
  if(N > 0)
    os << a[N - 1];
  os << "]";
  return os;
}
 
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, const std::pair<T1, T2>& p) {
  os << "(" << p.first << ", " << p.second << ") ";
  return os;
}
 
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << '[';
  for(auto x : v)
    os << x << ", ";
  os << "] ";
  return os;
}
 
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& s) {
  os << "{";
  for(auto x : s)
    os << x << ", ";
  os << "} ";
  return os;
}
//
template<typename T, typename cmp>
std::ostream& operator<<(std::ostream& os, const std::set<T, cmp>& s) {
  os << "{";
  for(auto x : s)
    os << x << ", ";
  os << "} ";
  return os;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Runtime error 19 ms 5364 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 0 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -