Submission #232077

# Submission time Handle Problem Language Result Execution time Memory
232077 2020-05-16T01:09:15 Z anonymous Gondola (IOI14_gondola) C++14
100 / 100
72 ms 6020 KB
#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);
}

Compilation message

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 time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 19 ms 2304 KB Output is correct
7 Correct 16 ms 640 KB Output is correct
8 Correct 35 ms 3968 KB Output is correct
9 Correct 13 ms 1536 KB Output is correct
10 Correct 41 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 19 ms 2176 KB Output is correct
7 Correct 16 ms 640 KB Output is correct
8 Correct 32 ms 3960 KB Output is correct
9 Correct 13 ms 1536 KB Output is correct
10 Correct 42 ms 4600 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 23 ms 2040 KB Output is correct
14 Correct 5 ms 256 KB Output is correct
15 Correct 53 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1328 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 6 ms 1280 KB Output is correct
5 Correct 5 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 6 ms 1280 KB Output is correct
5 Correct 5 ms 1280 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 5 ms 1280 KB Output is correct
9 Correct 5 ms 1280 KB Output is correct
10 Correct 6 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1280 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 5 ms 1280 KB Output is correct
4 Correct 5 ms 1280 KB Output is correct
5 Correct 5 ms 1280 KB Output is correct
6 Correct 5 ms 1280 KB Output is correct
7 Correct 5 ms 1280 KB Output is correct
8 Correct 5 ms 1408 KB Output is correct
9 Correct 5 ms 1280 KB Output is correct
10 Correct 5 ms 1408 KB Output is correct
11 Correct 15 ms 1920 KB Output is correct
12 Correct 17 ms 2048 KB Output is correct
13 Correct 18 ms 2304 KB Output is correct
14 Correct 18 ms 1920 KB Output is correct
15 Correct 24 ms 3200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 4 ms 256 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 5 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 52 ms 4088 KB Output is correct
10 Correct 41 ms 3456 KB Output is correct
11 Correct 18 ms 1408 KB Output is correct
12 Correct 21 ms 1664 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 4 ms 256 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 52 ms 4088 KB Output is correct
10 Correct 41 ms 3452 KB Output is correct
11 Correct 17 ms 1408 KB Output is correct
12 Correct 21 ms 1664 KB Output is correct
13 Correct 8 ms 640 KB Output is correct
14 Correct 67 ms 5508 KB Output is correct
15 Correct 72 ms 6020 KB Output is correct
16 Correct 15 ms 1408 KB Output is correct
17 Correct 48 ms 4216 KB Output is correct
18 Correct 28 ms 2432 KB Output is correct