답안 #833000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833000 2023-08-21T18:50:53 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;
}

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: In function 'int replacement(int, int*, int*)':
gondola.cpp:59:17: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |   int val = arr[pos];
      |                 ^~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:129:17: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
  129 |   int val = arr[pos];
      |                 ^~~
/usr/bin/ld: /tmp/ccEHa6Qj.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