답안 #922865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
922865 2024-02-06T08:29:29 Z allin27x 곤돌라 (IOI14_gondola) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
//#include "gondola.h"

int valid(int n, int S[]){
	set<int> s; for(int i=0; i<n; i++) s.insert(S[i]); if (s.size()<n) return 0;
	int ind = -1;
	for (int i=0; i<n; i++) if (S[i] <= n) {ind = i; break;}
	if (ind == -1) return 1;
	int t = S[ind];
	for (int i=ind+1; i!=ind; i++, i%=n){
		t++; if (t==n+1) t = 1;
		if (S[i] <= n && S[i] != t) return 0;
	}
	return 1;
}



int replacement(int n, int S[], int replacementSeq[]){
	int ind = -1;
	for (int i=0; i<n; i++) if (S[i] <= n) {ind = i; break;}
	if (ind == -1) return 1;
	int t = S[ind];
	map<int,int> tr; int bg = -1;
	for (int i=ind+1; i!=ind; i++, i%=n){
		t++; if (t==n+1) t = 1;
		if (S[i] > n) {tr[S[i]] = t; bg=max(bg,S[i]);}
	}
	if (bg==-1) return 0;
	int bgm = tr[bg];
	for (int i=n+1; i<=bg; i++){
		if (tr.count(i)){
			replacementSeq[i-(n+1)] = tr[i];
		} else {
			replacementSeq[i-(n+1)] = bgm;
			bgm = i; tr[bg] = i;
		}
	}
	return (bg-(n+1) + 1);

}

int countReplacement(int n, int inputSeq[]){
	return 0;
}


// int main(){
// 	int S[] = {3,1,4};
// 	int ans[10];
// 	int k = replacement(3,S,ans);
// 	for (int i=0; i<k; i++) cout<<ans[i]<<' ';
// }

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:6:65: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    6 |  set<int> s; for(int i=0; i<n; i++) s.insert(S[i]); if (s.size()<n) return 0;
      |                                                         ~~~~~~~~^~
/usr/bin/ld: /tmp/ccYE0agd.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