Submission #30334

# Submission time Handle Problem Language Result Execution time Memory
30334 2017-07-23T08:56:43 Z inqr Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rt insert
#define st first
#define nd second
#define ll long long
#define pii pair < int , int >
#define DB printf("debug\n");
#define umax( x , y ) x = max( x , (y) )
#define umin( x , y ) x = min( x , (y) )
#define all(x) x.begin() , x.end()
using namespace std;
int nx(int i,int sz){
	return (i+1)%(sz);
}
map < int,int > timesseen;
int valid(int n, int inputSeq[])
{
	vector < int > orig;
	for(int i=0;i<n;i++){
		int nxx=nx(i,n);
		timesseen[inputSeq[i]]++;
		if(timesseen[inputSeq[i]]>1)return 0;
		if(inputSeq[i]<=n)orig.pb(inputSeq[i]);
		if(inputSeq[i]<=n&&inputSeq[nxx]<=n){
			if(inputSeq[i]==n && inputSeq[nxx]!=1)return 0;
			else if(inputSeq[i]<n && inputSeq[nxx]!=inputSeq[i]+1)return 0;
		}
	}
	int startover=0;
	for(int i=0;i<orig.size();i++){
		int nxx=nx(i,orig.size());
		if(orig[i]<orig[nxx])continue;
		else if(startover==0)startover++;
		else if(startover==1)return 0;
	}
 	return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
	int origl=-1;
	int broken=0;
	for(int i=0;i<n;i++){
		int nxx=nx(i,n);
		if(inputSeq[i]<=n){
			origl=i-(inputSeq[i]-1)+n;
			origl%=n;
		}
		umax(broken,inputSeq[i]-n);
	}
	if(origl==-1)origl=0;

	int repind[broken];
	set < int > repcand;
	int orig[n];
	for(int i=0;i<n;i++){
		int ogon=(i+1)-origl+n;
		if(ogon>n)ogon%=n;
		orig[i]=ogon;
		if(gondolaSeq[i]>n){
			repcand.insert(i);
			repind[gondolaSeq[i]-n-1]=i;
		}
	}
	for(int i=0;i<broken;i++){
		if(!repind[i]){
			replacementSeq[i]=ogon[repcand.begin()->st];
			orig[repcand.begin()->st]=i+n+1;
		}
		else{
			replacementSeq[i]=ogon[repind[i]];
			orig[repind[i]]=i+n+1;
			repcand.erase(repcand.find(repind[i]));
		}
	}
	return broken;
}

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

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

Compilation message

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<orig.size();i++){
               ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:50:6: error: 'inputSeq' was not declared in this scope
   if(inputSeq[i]<=n){
      ^
gondola.cpp:54:15: error: 'inputSeq' was not declared in this scope
   umax(broken,inputSeq[i]-n);
               ^
gondola.cpp:11:37: note: in definition of macro 'umax'
 #define umax( x , y ) x = max( x , (y) )
                                     ^
gondola.cpp:49:7: warning: unused variable 'nxx' [-Wunused-variable]
   int nxx=nx(i,n);
       ^
gondola.cpp:72:22: error: 'ogon' was not declared in this scope
    replacementSeq[i]=ogon[repcand.begin()->st];
                      ^
gondola.cpp:6:12: error: request for member 'first' in '* repcand.std::set<_Key, _Compare, _Alloc>::begin<int, std::less<int>, std::allocator<int> >().std::_Rb_tree_const_iterator<_Tp>::operator-><int>()', which is of non-class type 'const int'
 #define st first
            ^
gondola.cpp:72:44: note: in expansion of macro 'st'
    replacementSeq[i]=ogon[repcand.begin()->st];
                                            ^
gondola.cpp:6:12: error: request for member 'first' in '* repcand.std::set<_Key, _Compare, _Alloc>::begin<int, std::less<int>, std::allocator<int> >().std::_Rb_tree_const_iterator<_Tp>::operator-><int>()', which is of non-class type 'const int'
 #define st first
            ^
gondola.cpp:73:26: note: in expansion of macro 'st'
    orig[repcand.begin()->st]=i+n+1;
                          ^
gondola.cpp:76:22: error: 'ogon' was not declared in this scope
    replacementSeq[i]=ogon[repind[i]];
                      ^