Submission #91167

# Submission time Handle Problem Language Result Execution time Memory
91167 2018-12-26T12:37:09 Z arman_ferdous Gondola (IOI14_gondola) C++17
Compilation error
0 ms 0 KB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

set<int> st;
int valid(int n, int inputSeq[]) {
	int last = -1, start = -1, num = 1000000;
	for(int i = 0; i < n; i++) {
		st.insert(inputSeq[i]);
		if(inputSeq[i] > n) inputSeq[i] = -1;
		else {
			last = i;
			if(inputSeq[i] < num) 
				start = i, num = inputSeq[i];
		}
	}
	if(st.size() != n) return 0;
	if(last == -1) return 1;
	for(int i = start; i < n; i++)
		if(inputSeq[i] + 1 && inputSeq[i] != num + i - start)
			return 0;
	int at0 = inputSeq[last] + n - last;
	for(int i = 0; i < start; i++)
		if(inputSeq[i] + 1 && inputSeq[i] != at0 + i)
			return 0;

  	return 1;
}

int init[100001];
vector< pair<int,int> > v;
int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
	int start = -1;
 	for(int i = 0; i < n; i++) if(gondolaSeq[i] <= n) {
		start = i - gondolaSeq[i] + 1;
		if(start < 0) start += n;
		break;
	} if(start == -1) start = 0;
	int cur = 1;
 	for(int i = start; i < n; i++) init[i] = cur++;
 	for(int i = 0; i < start; i++) init[i] = cur++;

 	for(int i = 0; i < n; i++) if(gondolaSeq[i] > n)
 		v.push_back({gondolaSeq[i], i});
 	sort(v.begin(), v.end());

 	int ptr = 0;
 	for(auto it : v) {
 		while(cur <= it.first) {
 			replacement[ptr++] = init[it.second];
 			init[it.second] = cur;
 			cur++;
 		}
 	} return ptr;
}

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

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:17:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(st.size() != n) return 0;
     ~~~~~~~~~~^~~~
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:50:22: warning: pointer to a function used in arithmetic [-Wpointer-arith]
     replacement[ptr++] = init[it.second];
                      ^
gondola.cpp:50:40: error: assignment of read-only location '*(replacement + ((sizetype)(ptr ++)))'
     replacement[ptr++] = init[it.second];
                                        ^
gondola.cpp:50:40: error: cannot convert 'int' to 'int(int, int*, int*)' in assignment