답안 #833007

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833007 2023-08-21T19:01:10 Z Halym2007 곤돌라 (IOI14_gondola) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define sz size()
#define pb push_back
#define ll long long
map <int, bool> m;

ll md = 1e9 + 9;

int valid(int n, int inputSeq[]) {
	int ind = -1;
	for (int i = 0; i < n; ++i) {
		if (m[inputSeq[i]]) return 0;
		m[inputSeq[i]] = 1;
	}
	for (int i = 0; i < n; ++i) {
		if (inputSeq[i] <= n) {
			ind = i;
			break;
		}
	}
	if (ind == -1) return 1;
	int val = inputSeq[ind] - 1;
	for (int i = 0; i < n; ++i) {
		if (inputSeq[ind] <= n and (val + 1) != inputSeq[ind]) {
			return 0;
		}
		ind++;
		val++;
		ind %= n;
		val %= n;
	}
	return 1;
}

int replacement(int n, int arr[], int rep[]) {
	int mx = -1, mn = 1e9;
	for (int i = 0; i < n; ++i) {
		mx = max(mx, arr[i]);
		mn = min (mn, arr[i]);
	}
	int o = 0;
	if (mx <= n) 
		return 0;
	vector <int> orig(n, 0);
	if (mn > n) {
		for (int i = 0; i < n; ++i) {
			orig[i] = i + 1;
		}
	} 
	else {
		int pos;
		for (int i = 0; i < n; ++i) {
			if (arr[i] <= n) {
				pos = i;
				break;
			}
		}
		int val = arr[pos];
		for (int i = 0; i < n; ++i) {
			orig[pos] = val;
			pos++;
			val++;
			if (val > n) val = 1;
			if (pos == n) pos = 0;
		}
	}
	vector <int> idx;
	for (int i = 0; i < n; ++i) {
		if (arr[i] > n) {
			idx.pb (i);
		}
	}
	sort (idx.begin(), idx.end(), [&] (int x, int y) {
		return (arr[x] < arr[y]);	
	});
	int last = n + 1;
	for (int i = 0; i < (int)idx.sz; ++i) {
		rep[o++] = orig[idx[i]];
		
		while (last < arr[idx[i]]) {
			rep[o++] = last++;
		}
		last++;
	}
	return o;
}


ll solve (int x, int y) {
	if (y == 0) return 1;
	ll jp = solve (x, y / 2); 
	jp *= jp;
	jp %= md;
	if (y % 2 == 1) {
		jp *= x;
		jp %= md;
	}
	return jp;
}


int countReplacement(int n, int arr[]) {
	if (!valid(n, arr)) {
		return 0;
	}
	int mx = 0, mn = 1e9;
	for (int i = 0; i < n; ++i) {
		mx = max(mx, arr[i]);
		mn = min (mn, arr[i]);
	}
	int o = 0;
	if (mx <= n) 
		return 1;
	vector <int> orig(n, 0);
	if (mn > n) {
		for (int i = 0; i < n; ++i) {
			orig[i] = i + 1;
		}
	} 
	else {
		int pos;
		for (int i = 0; i < n; ++i) {
			if (arr[i] <= n) {
				pos = i;
				break;
			}
		}
		int val = arr[pos];
		for (int i = 0; i < n; ++i) {
			orig[pos] = val;
			pos++;
			val++;
			if (val > n) val = 1;
			if (pos == n) pos = 0;
		}
	}
	vector <int> idx;
	for (int i = 0; i < n; ++i) {
		if (arr[i] > n) {
			idx.pb (i);
		}
	}
	sort (idx.begin(), idx.end(), [&] (int x, int y) {
		return (arr[x] < arr[y]);	
	});
	ll jogap = 1;
	if (mn > n) jogap = n;
	int last = n + 1;
	for (int i = 0; i < (int)idx.sz; ++i) {
		ll jj = idx.sz - i;
		ll ii = (arr[idx[i]]-1) - last + 1;
		ll kp = solve (jj, ii);
		if (kp == 0) kp = 1;
		jogap *= kp;
//		jogap *= (ii * jj) % md;
		jogap %= md;
		last = arr[idx[i]] + 1;
	}
	return jogap;
}
		return (arr[x] < arr[y]);	
	});
	ll jogap = 1;
	if (mn > n) jogap = n;
	int last = n + 1;
	for (int i = 0; i < (int)idx.sz; ++i) {
		ll jj = idx.sz - i;
		ll ii = (arr[idx[i]]-1) - last + 1;
		ll kp = solve (jj, ii);
		if (kp == 0) kp = 1;
		jogap *= kp;
//		jogap *= (ii * jj) % md;
		jogap %= md;
		last = arr[idx[i]] + 1;
		

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:112:6: warning: unused variable 'o' [-Wunused-variable]
  112 |  int o = 0;
      |      ^
gondola.cpp: At global scope:
gondola.cpp:162:3: error: expected unqualified-id before 'return'
  162 |   return (arr[x] < arr[y]);
      |   ^~~~~~
gondola.cpp:163:2: error: expected declaration before '}' token
  163 |  });
      |  ^
gondola.cpp:163:3: error: expected unqualified-id before ')' token
  163 |  });
      |   ^
gondola.cpp:165:2: error: expected unqualified-id before 'if'
  165 |  if (mn > n) jogap = n;
      |  ^~
gondola.cpp:166:13: error: 'n' was not declared in this scope
  166 |  int last = n + 1;
      |             ^
gondola.cpp:167:2: error: expected unqualified-id before 'for'
  167 |  for (int i = 0; i < (int)idx.sz; ++i) {
      |  ^~~
gondola.cpp:167:18: error: 'i' does not name a type
  167 |  for (int i = 0; i < (int)idx.sz; ++i) {
      |                  ^
gondola.cpp:167:35: error: expected unqualified-id before '++' token
  167 |  for (int i = 0; i < (int)idx.sz; ++i) {
      |                                   ^~