제출 #232077

#제출 시각아이디문제언어결과실행 시간메모리
232077anonymous곤돌라 (IOI14_gondola)C++14
100 / 100
72 ms6020 KiB
#include "gondola.h"
#include <vector>
#include <iostream>
#include <set>
#define MAXN 100005
#define MAXV 250005
using namespace std;

int valid(int n, int Seq[])
{
  bool b = false;
  set <int> S;
  int pos, v;
  for (int i=0; i<n; i++) {
      if (Seq[i] <= n) {
            pos = i;
            v = Seq[i];
      }
      if (S.find(Seq[i]) != S.end()) {return(0);}
      S.insert(Seq[i]);

  }
  for (int i=0; i<n; i++) {
    if (Seq[pos] > n) {}
    else if (Seq[pos] != v) {return(0);}
    pos = (pos+1) %n;
    v= v == n ? 1 : v+1;
  }
  return(1);
}

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

int replacement(int n, int Seq[], int ans[])
{
  int mx = 0, first=0, pos[MAXV]={}, Cur[MAXN];
  bool b = false;
  for (int i=0; i<n; i++) {
    if (Seq[i] > n) {
        pos[Seq[i]] = i+1;
        if (!first) {first = i+1;}
    } else if (!b) {
        int p = i+1, v = Seq[i];
        for (int j=0; j<n; j++) {
            Cur[p] = v;
            p = p == n ? 1: p+1;
            v = v == n ? 1: v+1;
        }
        b=true;
    }
    mx = max(mx, Seq[i]);
  }
  if (!b) {
    for (int i=1; i<=n; i++) {Cur[i] = i;}
  }
  for (int i=n+1; i<=mx; i++) {
    if (pos[i] == 0) {
        ans[i - n - 1] = Cur[first];
        Cur[first] = i;
    } else {
        ans[i - n - 1] = Cur[pos[i]];
        Cur[pos[i]] = i;
        while (Cur[first] == Seq[first-1]) {first++;}
    }
  }
  return(mx - n);
}

//----------------------
#define LL long long
#define MOD 1000000009
#include <algorithm>
LL modexp(LL x, LL k) { //x^k, can be optimised
    if (k == 0) {return(1);}
    else if (k%2) {
        LL v = modexp(x,k/2);
        return((((v*v)%MOD)*x)%MOD);
    } else {
        LL v = modexp(x,k/2);
        return((v*v)%MOD);
    }
}

int countReplacement(int n, int Seq[])
{
  if (!valid(n, Seq)) {return(0);}
  int num = n, cur = n;
  vector <int> Val;
  for (int i=0; i<n; i++) {
     if (Seq[i] > n) {Val.push_back(Seq[i]);}
     else {
        num --, cur--;
     }
  }
  Val.push_back(n);
  sort(Val.begin(), Val.end());
  LL res = 1;
  for (int i=1; i<Val.size(); i++) {
      res = (res * modexp(cur, Val[i] - Val[i-1]-1)) % MOD;
      cur --;
  }
  if (num == n) {res = (res * n) %MOD;}
  return(res);
}

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

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:11:8: warning: unused variable 'b' [-Wunused-variable]
   bool b = false;
        ^
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:98:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i=1; i<Val.size(); i++) {
                 ~^~~~~~~~~~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:27:15: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
     v= v == n ? 1 : v+1;
        ~~~~~~~^~~~~~~~~
gondola.cpp:24:16: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (Seq[pos] > n) {}
                ^
#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...