Submission #152533

# Submission time Handle Problem Language Result Execution time Memory
152533 2019-09-08T09:32:49 Z Nightlight Gondola (IOI14_gondola) C++14
Compilation error
0 ms 0 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define MOD 1000000009;
using namespace std;

int exist[250001];
unordered_set<int> existA;

int valid(int n, int inputSeq[])
{
  int idx = 0;
  for(int i = 0; i < n; i++){
    if(exist[inputSeq[i]] == 1)return 0;
    exist[inputSeq[i]] = 1;
    if(!idx && inputSeq[i] <= n)
      idx = inputSeq[i] + 1;
    else{
      if(idx > n)idx = 1;
      if(inputSeq[i] <= n && inputSeq[i] != idx)
        return 0;
      if(idx)idx++;
    }
  }
  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[])
{
  int idx = 0, MAX = 0, MAXid;
  for(int i = 0; i < n; i++){
    if(gondolaSeq[i] <= n){
      idx = gondolaSeq[i] - i;
      if(idx < 1) idx += n;
      break;
    }
  }
  if(!idx)idx = 1;
  for(int i = 0; i < n; i++){
    if(idx > n)idx = 1;
    if(gondolaSeq[i] > MAX){
      MAX = gondolaSeq[i];
      MAXid = idx;
    }
    if(gondolaSeq[i] > n){
      exist[gondolaSeq[i]] = idx;
//      cout << gondolaSeq[i] << " " << exist[gondolaSeq[i]] << "\n";
    }
    idx++;
  }
  if(MAX == n)return 0;
  else{
    int MAXin = 0, last = 0;
    exist[MAX] = 0;
    for(int i = n+1; i <= MAX; i++){
//      cout << i << " " << exist[i] << "\n";
      if(exist[i]){
        replacementSeq[i-n-1] = exist[i];
      }else{
        if(!MAXin){
          replacementSeq[i-n-1] = MAXid;
          MAXin = 1; 
        }else{
          replacementSeq[i-n-1] = last;
        }
        last = i;
      }
    }
  }
  return MAX - n;
}

//----------------------
vector<long long> replaced;

long long int pow( long long int a, long long int x ){
	long long res = 1;
	while(x){
    if(x&1)
      res *= a;
    x >>= 1;
    a *= a;
  }
  return res;
}

int countReplacement(int n, int inputSeq[])
{
  int idx = 0;
  replaced.push_back(n);
  for(int i = 0; i < n; i++){
    if(existA.count(inputSeq[i]))return 0;
    existA.insert(inputSeq[i]);
    if(inputSeq[i] > n){
      replaced.push_back(inputSeq[i]);
    if(!idx && inputSeq[i] <= n){
      idx = inputSeq[i] + 1;
    }else{
      if(idx > n)idx = 1;
      }else if(inputSeq[i] <= n && inputSeq[i] != idx)
        return 0;
      if(idx)idx++;
    }
  }
  sort(replaced.begin() + 1, replaced.end());
  long long ans = (idx ? 1 : n);
  for(int i = 1; i < replaced.size(); i++){
    ans *= pow(replaced.size() - i,replaced[i] - replaced[i-1] - 1);
    ans %= MOD;
  }
  return ans;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:101:8: error: expected '}' before 'else'
       }else if(inputSeq[i] <= n && inputSeq[i] != idx)
        ^~~~
gondola.cpp: At global scope:
gondola.cpp:106:7: error: expected constructor, destructor, or type conversion before '(' token
   sort(replaced.begin() + 1, replaced.end());
       ^
gondola.cpp:107:20: error: 'idx' was not declared in this scope
   long long ans = (idx ? 1 : n);
                    ^~~
gondola.cpp:107:20: note: suggested alternative: 'index'
   long long ans = (idx ? 1 : n);
                    ^~~
                    index
gondola.cpp:107:30: error: 'n' was not declared in this scope
   long long ans = (idx ? 1 : n);
                              ^
gondola.cpp:107:30: note: suggested alternative: 'yn'
   long long ans = (idx ? 1 : n);
                              ^
                              yn
gondola.cpp:108:3: error: expected unqualified-id before 'for'
   for(int i = 1; i < replaced.size(); i++){
   ^~~
gondola.cpp:108:18: error: 'i' does not name a type
   for(int i = 1; i < replaced.size(); i++){
                  ^
gondola.cpp:108:39: error: 'i' does not name a type
   for(int i = 1; i < replaced.size(); i++){
                                       ^
gondola.cpp:112:3: error: expected unqualified-id before 'return'
   return ans;
   ^~~~~~
gondola.cpp:113:1: error: expected declaration before '}' token
 }
 ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:105:3: warning: control reaches end of non-void function [-Wreturn-type]
   }
   ^