Submission #866835

# Submission time Handle Problem Language Result Execution time Memory
866835 2023-10-27T08:32:09 Z Onur_Ilgaz Gondola (IOI14_gondola) C++17
75 / 100
67 ms 5464 KB
#include "gondola.h"
#include <bits/stdc++.h>
#define inf INT_MAX
#define ll long long
using namespace std;

int valid(int n, int arr[])
{
  int ind = 0, mn = inf;
  set <int> st;
  for(int i = 0; i < n; i++) {
    if(arr[i] < mn) ind = i, mn = arr[i];
    if(st.count(arr[i])) return 0;
    st.insert(arr[i]);
  }
  int now = mn + 1;
  // cout<<ind<<" "<<now<<" ";
  for(int i = (ind + 1) % n; i % n != ind; i = (i + 1) % n, now++) {
    if(arr[i] <= n and arr[i] != now) {
        return 0;
    }
  }
  return 1;
}

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

bool hello = 0;

int replacement(int n, int arr[], int ans[])
{
  map <int, int> mp;
  int mxi = 0, mx = 0;
  int shift = 0;
  for(int i = 0; i < n; i++) {
    mp[arr[i]] = i;
    if(arr[i] > mx) mxi = i, mx = arr[i];
    if(arr[i] <= n) {
      shift = (arr[i] - i - 1) % n;
    }
  }
  int l = mx;
  if(hello) return l - n;
  mxi = (mxi + shift + n) % n + 1;
  for(int i = n + 1; i <= l; i++) {
    int val;
    if(mp.count(i)) {
      if(i == mx) val = mxi;
      else val = (mp[i] + shift + n) % n + 1;
    }
    else {
      val = mxi;
      mxi = i;
    }
    // cout<<val<<" "<<shift<<"\n";
    ans[i - (n + 1)] = val;
  }
  return l - n;
}

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

const int mod = 1000000009;

void duzelt(int n, int arr[]) {
  vector <int> brr(n);
  int ind = 0, mn = inf;
  for(int i = 0; i < n; i++) {
    if(arr[i] < mn) ind = i, mn = arr[i];
  }
  ind = (ind - (mn - 1) + n) % n;
  int to = 0, i;
  for(i = (ind + 1) % n; i != ind; i = (i + 1) % n, to++) {
    brr[to] = arr[(i - 1 + n) % n];
  }
  brr[to] = arr[(i - 1 + n) % n];
  for(int i = 0; i < n; i++) arr[i] = brr[i];
}

int binpow(ll x, ll y) {
  ll ret = 1;
  while(y) {
    if(y & 1) {
       ret *= x;
       ret %= mod;
    }
    x *= x;
    x %= mod;
    y /= 2;
  }
  return ret;
}

int countReplacement(int n, int arr[])
{
    if(!valid(n, arr)) return 0;
    int ans[1];
    hello = 1;
    if(!replacement(n, arr, ans)) return 1;
    duzelt(n, arr);
    set <int> st;
    for(int i = 0; i < n; i++) {
      if(arr[i] > n) st.insert(arr[i]);
    }
    int prev = n, len = st.size();
    ll ret = 1;
    for(auto till:st) {
      int diff = till - prev - 1;
      ret *= binpow(len, diff);
      ret %= mod;
      prev = till;
      len--;
    }
    return ret;
}










# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 424 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 13 ms 2396 KB Output is correct
7 Correct 9 ms 1096 KB Output is correct
8 Correct 22 ms 4436 KB Output is correct
9 Correct 6 ms 1624 KB Output is correct
10 Correct 25 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 10 ms 2500 KB Output is correct
7 Correct 7 ms 1116 KB Output is correct
8 Correct 20 ms 4444 KB Output is correct
9 Correct 7 ms 1628 KB Output is correct
10 Correct 26 ms 5060 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 12 ms 2396 KB Output is correct
14 Correct 0 ms 444 KB Output is correct
15 Correct 31 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 440 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 17 ms 4872 KB Output is correct
12 Correct 19 ms 5464 KB Output is correct
13 Correct 21 ms 2908 KB Output is correct
14 Correct 18 ms 4756 KB Output is correct
15 Correct 21 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 440 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 59 ms 4484 KB Output is correct
10 Correct 43 ms 3672 KB Output is correct
11 Correct 20 ms 1628 KB Output is correct
12 Correct 19 ms 1880 KB Output is correct
13 Runtime error 4 ms 1112 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 400 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 67 ms 4636 KB Output is correct
10 Correct 47 ms 3968 KB Output is correct
11 Correct 17 ms 1628 KB Output is correct
12 Correct 19 ms 1884 KB Output is correct
13 Runtime error 4 ms 1264 KB Execution killed with signal 11
14 Halted 0 ms 0 KB -