Submission #39717

# Submission time Handle Problem Language Result Execution time Memory
39717 2018-01-18T01:44:34 Z funcsr Gondola (IOI14_gondola) C++14
100 / 100
74 ms 13336 KB
#include "gondola.h"
#include <iostream>
#include <vector>
#include <cassert>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000009
#define _1 first
#define _2 second

int A[100000], cur[100000];
map<int, int> cnt;
bool glock;
int valid(int N, int inputSeq[]) {
  cnt.clear();
  rep(i, N) A[i] = inputSeq[i]-1;
  rep(i, N) cnt[A[i]]++;
  for (P p : cnt) if (p._2 > 1) return 0;
  int base = -1;
  rep(i, N) if (A[i] < N) base = (A[i]-i+N)%N;
  rep(i, N) cur[i] = (i+max(0,base))%N;
  glock = false;
  if (base == -1) return 1;
  glock = true;
  rep(i, N) if (A[i] < N && A[i] != cur[i]) return 0;
  return 1;
}

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

int rev[250000];
int replacement(int N, int gondolaSeq[], int replacementSeq[]) {
  set<int> unused;
  assert(valid(N, gondolaSeq));
  rep(i, N) rev[A[i]] = i;
  rep(i, N) if (A[i] >= N) unused.insert(i);
  int m = *max_element(A, A+N);
  int c = 0;
  for (int i=N; i<=m; i++) {
    int p = -1;
    if (cnt[i]) {
      p = rev[i];
      unused.erase(rev[i]);
    }
    else p = *unused.begin();
    replacementSeq[c++] = cur[p]+1;
    cur[p] = i;
  }
  return c;
}

//----------------------
int modpow(int x, int k) {
  int a = 1;
  while (k) {
    if (k&1) a = (1LL*a*x)%MOD;
    x = (1LL*x*x)%MOD;
    k>>=1;
  }
  return a;
}

int countReplacement(int N, int inputSeq[]) {
  if (valid(N, inputSeq) == 0) return 0;
  int unused = 0;
  rep(i, N) if (A[i] >= N) unused++;
  int m = *max_element(A, A+N);
  int s = 1;
  if (!glock) s *= N;
  int c = 0;
  int lp = N-1;
  for (P p : cnt) {
    if (p._1 < N) continue;
    s = (1LL*s*modpow(unused, p._1-lp-1)) % MOD;
    unused--;
    lp = p._1;
  }
  return s;
}

Compilation message

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:72:7: warning: unused variable 'm' [-Wunused-variable]
   int m = *max_element(A, A+N);
       ^
gondola.cpp:75:7: warning: unused variable 'c' [-Wunused-variable]
   int c = 0;
       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
6 Correct 15 ms 6868 KB Output is correct
7 Correct 31 ms 8188 KB Output is correct
8 Correct 16 ms 8452 KB Output is correct
9 Correct 7 ms 6208 KB Output is correct
10 Correct 32 ms 9112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
6 Correct 13 ms 6868 KB Output is correct
7 Correct 26 ms 8188 KB Output is correct
8 Correct 18 ms 8452 KB Output is correct
9 Correct 7 ms 6208 KB Output is correct
10 Correct 23 ms 9112 KB Output is correct
11 Correct 0 ms 5152 KB Output is correct
12 Correct 0 ms 5152 KB Output is correct
13 Correct 13 ms 6868 KB Output is correct
14 Correct 0 ms 5152 KB Output is correct
15 Correct 51 ms 9244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
6 Correct 0 ms 5152 KB Output is correct
7 Correct 1 ms 5284 KB Output is correct
8 Correct 1 ms 5416 KB Output is correct
9 Correct 1 ms 5284 KB Output is correct
10 Correct 1 ms 5416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
6 Correct 0 ms 5152 KB Output is correct
7 Correct 1 ms 5284 KB Output is correct
8 Correct 1 ms 5416 KB Output is correct
9 Correct 1 ms 5284 KB Output is correct
10 Correct 1 ms 5416 KB Output is correct
11 Correct 26 ms 8848 KB Output is correct
12 Correct 37 ms 9376 KB Output is correct
13 Correct 50 ms 9244 KB Output is correct
14 Correct 30 ms 8848 KB Output is correct
15 Correct 74 ms 13336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
6 Correct 0 ms 5152 KB Output is correct
7 Correct 0 ms 5152 KB Output is correct
8 Correct 0 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 0 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
6 Correct 0 ms 5152 KB Output is correct
7 Correct 0 ms 5152 KB Output is correct
8 Correct 0 ms 5152 KB Output is correct
9 Correct 43 ms 8584 KB Output is correct
10 Correct 29 ms 8056 KB Output is correct
11 Correct 12 ms 6208 KB Output is correct
12 Correct 16 ms 6472 KB Output is correct
13 Correct 3 ms 5416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5152 KB Output is correct
2 Correct 4 ms 5152 KB Output is correct
3 Correct 0 ms 5152 KB Output is correct
4 Correct 0 ms 5152 KB Output is correct
5 Correct 0 ms 5152 KB Output is correct
6 Correct 0 ms 5152 KB Output is correct
7 Correct 0 ms 5152 KB Output is correct
8 Correct 0 ms 5152 KB Output is correct
9 Correct 42 ms 8584 KB Output is correct
10 Correct 29 ms 8056 KB Output is correct
11 Correct 12 ms 6208 KB Output is correct
12 Correct 16 ms 6472 KB Output is correct
13 Correct 1 ms 5416 KB Output is correct
14 Correct 46 ms 9112 KB Output is correct
15 Correct 54 ms 9640 KB Output is correct
16 Correct 11 ms 5944 KB Output is correct
17 Correct 40 ms 8188 KB Output is correct
18 Correct 20 ms 6868 KB Output is correct