Submission #794359

# Submission time Handle Problem Language Result Execution time Memory
794359 2023-07-26T13:22:47 Z medmdg Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1000010;
const int mod = 1000000009;
typedef pair<int, int> ii;

int modpow(int x, int y) {
	if (y == 0) return 1;
	if (y == 1) return x;
	int ret = modpow(x, y / 2);
	ret = 1LL * ret * ret % mod;
	if (y % 2) ret = 1LL * ret * x % mod;
	return ret;
}

int n;
int ar[MAXN];

set<int> there;
bool valid() {
	ar[n] = ar[0];
	for (int i = 0; i < n; i++) {
		if (there.count(ar[i])) return false;
		there.insert(ar[i]);
		if (ar[i] < n && (ar[i + 1] != ar[i] + 1 && ar[i + 1] <= n)) {
			return false;
		}
		if (ar[i] == n && (ar[i + 1] != 1 && ar[i + 1] <= n)) {
			return false;
		}
	}
	return true;
}

void replacement() {
	vector<ii> repl;
	bool fail = false;
	do {
		if (fail) {
			repl.emplace_back(ar[0], 1);
			ar[0] = 1;
		}
		for (int z = 0; z < 2 * n; z++) {
			int i = z % n;
			int j = (z + 1) % n;
			if (ar[i] > n) continue;
			if (ar[j] != ar[i] % n + 1) {
				repl.emplace_back(ar[j], ar[i] % n + 1);
				ar[j] = ar[i] % n + 1;
			}
		}
		fail = ar[0] > n;
	} while (fail);
	sort(repl.begin(), repl.end());
	int last = n + 1;
	vector<int> ans;
	for (int i = 0; i < repl.size(); i++) {
		while (repl[i].second < repl[i].first) {
			ans.push_back(repl[i].second);
			repl[i].second = last++;
		}
	}
	printf("%d", (int)ans.size());
	for (int i = 0; i < ans.size(); i++) {
		printf(" %d", ans[i]);
	}
	puts("");
}

int countReplacement() {
	if (!valid()) return 0;
	vector<int> big;
	for (int i = 0; i < n; i++) {
		if (ar[i] > n) {
			big.push_back(ar[i]);
		}
	}
	sort(big.begin(), big.end());
	int ans = big.size() == n ? n : 1;
	int gond = big.size();
	int cur = n + 1;
	for (int i = 0; i < big.size(); i++) {
		int d = big[i] - cur;
		ans = 1LL * ans * modpow(gond, d) % mod;
		cur = big[i] + 1;
		gond--;
	}
	return ans;
}

int main() {
	int subtask;
	scanf("%d", &subtask);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", ar + i);
	}
	if (subtask >= 1 && subtask <= 3) {
		printf("%d\n", (int)valid());
	}
	if (subtask >= 4 && subtask <= 6) {
		replacement();
	}
	if (subtask >= 7 && subtask <= 10) {
		printf("%d\n", countReplacement());
	}
}

Compilation message

gondola.cpp: In function 'void replacement()':
gondola.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for (int i = 0; i < repl.size(); i++) {
      |                  ~~^~~~~~~~~~~~~
gondola.cpp:66:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |  for (int i = 0; i < ans.size(); i++) {
      |                  ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement()':
gondola.cpp:81:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   81 |  int ans = big.size() == n ? n : 1;
      |            ~~~~~~~~~~~^~~~
gondola.cpp:84:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |  for (int i = 0; i < big.size(); i++) {
      |                  ~~^~~~~~~~~~~~
gondola.cpp: In function 'int main()':
gondola.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   95 |  scanf("%d", &subtask);
      |  ~~~~~^~~~~~~~~~~~~~~~
gondola.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
gondola.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |   scanf("%d", ar + i);
      |   ~~~~~^~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccZ7xj5W.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc393NiV.o:gondola.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccZ7xj5W.o: in function `main':
grader.cpp:(.text.startup+0xb6): undefined reference to `valid'
/usr/bin/ld: grader.cpp:(.text.startup+0x108): undefined reference to `countReplacement'
/usr/bin/ld: grader.cpp:(.text.startup+0x132): undefined reference to `replacement'
collect2: error: ld returned 1 exit status