제출 #1357762

#제출 시각아이디문제언어결과실행 시간메모리
1357762Dan13llljws게임 (IOI14_game)C++20
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

bool normalize(int n, int a[]) {
	auto i = min_element(a, a + n) - a;
	if (a[i] > n) return false;
	int shift = (i - (a[i] - 1) + n) % n;
	rotate(a, a + shift, a + n);
	return true;
}

int valid(int n, int inputSeq[]) {
	unordered_set<int> seen(inputSeq, inputSeq + n);
	if (seen.size() != n) return 0;
	if (!normalize(n, inputSeq)) return 1;
	for (int i = 0; i < n; i++)
		if (inputSeq[i] <= n && inputSeq[i] - inputSeq[0] != i) return 0;
	return 1;
}

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	normalize(n, gondolaSeq);
	vector<int> idx;
	for (int i = 0; i < n; i++)
		if (gondolaSeq[i] > n) idx.push_back(i);
	int ans = 0;
	ranges::sort(idx, [&](int i, int j) { return gondolaSeq[i] < gondolaSeq[j]; });
	for (int i : idx) {
		int cur = i + 1;
		while(cur < gondolaSeq[i]) replacementSeq[ans] = cur, cur = n + ++ans;
	}
	return ans;
}

const int mod = 1e9 + 9;

int fpow(int x, int k) {
	int ret = 1;
	while(k) {
		if (k & 1) ret = 1LL * ret * x % mod;
		x = 1LL * x * x % mod, k >>= 1;
	}
	return ret;
}

int countReplacement(int n, int inputSeq[]) {
	bool random = normalize(n, inputSeq);
	vector<int> a;
	for (int i = 0; i < n; i++)
		if (inputSeq[i] > n) a.push_back(inputSeq[i] - n);
	if (a.empty()) return 1;
	int m = a.size();
	ranges::sort(a);
	int ans = fpow(m--, a[0] - 1);
	for (auto [last, cur] : a | views::adjacent<2>) {
		if (last == cur) return 0;
		ans = 1LL * ans * fpow(m--, cur - last - 1) % mod;
	}
	if (!random) ans = 1LL * ans * n % mod;
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

game.cpp: In function 'int countReplacement(int, int*)':
game.cpp:55:44: error: 'adjacent' is not a member of 'std::views'
   55 |         for (auto [last, cur] : a | views::adjacent<2>) {
      |                                            ^~~~~~~~
game.cpp:55:55: error: expected primary-expression before ')' token
   55 |         for (auto [last, cur] : a | views::adjacent<2>) {
      |                                                       ^