제출 #136575

#제출 시각아이디문제언어결과실행 시간메모리
136575mosesmayer곤돌라 (IOI14_gondola)C++17
55 / 100
24 ms2404 KiB
#include "gondola.h"
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ALL(x) x.begin(), x.end()
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;

int valid(int n, int inputSeq[]){
	vi a(inputSeq, inputSeq + n);

	// handle whether all values are unique
	vi b(a.begin(), a.end());
	sort(ALL(b)); b.erase(unique(ALL(b)), b.end());
	if (b.size() != a.size()) return 0;

	// handle min element
	vi::iterator mnit = min_element(a.begin(), a.end());
	int mn = *mnit, pos = mnit - a.begin();
	if (mn >= n) return 1;
	
	// rotate elements so that min is at first position.
	// now index i will be original position of (mn + i - 1)%n + 1;
	rotate(a.begin(), a.begin() + pos, a.end());
	// validity check
	for (int i = 0; i < n; i++){
		if (a[i] > n) continue;
		if (a[i] != ((mn + i - 1) % n + 1)) return 0;
	}
	return 1;
}

//----------------------

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
	vi a(gondolaSeq, gondolaSeq + n);
	// get length
	int len = (*max_element(a.begin(), a.end())) - n;

	vi::iterator mnit = min_element(a.begin(), a.end());
	int mn = *mnit, pos = mnit - a.begin();

	if (mn < n){
		rotate(a.begin(), a.begin() + pos, a.end());
	} else {
		pos = 0;
	}
	vector<pii> rep; // to be replaced
	for (int i = 0; i < n; i++){
		int oriNum = mn < n ? ((mn + i - 1) % n) + 1 : i+1;
		if (a[i] > n || a[i] != oriNum){
			rep.eb(a[i], oriNum);
		}
	}
	sort(rep.begin(), rep.end());
	int cur = n+1, idx = 0;
	for (int i = 0; i < rep.size(); i++){
		int prv = rep[i].se;
		while (cur <= rep[i].fi){
			replacementSeq[idx++] = prv;
			prv = cur;
			cur++;
		}
	}
	return len;
}

//----------------------

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

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

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:60:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < rep.size(); i++){
                  ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...