Submission #582769

#TimeUsernameProblemLanguageResultExecution timeMemory
582769drdilyorGondola (IOI14_gondola)C++17
60 / 100
39 ms5024 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#ifdef ONPC
    #define cerr cout
    #include "t_debug.cpp"
#else
    #define debug(...) 42
#endif
#define allit(a) (a).begin(), (a).end()
#define sz(a) ((int) (a).size())
#define cut(s) {cout << s << '\n'; return 0;}
#include "gondola.h"

using namespace std;
using ll = long long;
using vi = vector<int>;
namespace pd = __gnu_pbds;
template<typename K> using ordered_set = pd::tree<K, pd::null_type, less<K>, pd::rb_tree_tag, pd::tree_order_statistics_node_update>;
template<typename... T> using hash_table = pd::gp_hash_table<T...>;

const int INF = 1e9;
const ll INFL = 1e18;
const int N = 250000;
const int MOD = 1e9+7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

int valid(int n, int* a_) {
    vi a(n);
    for (int i = 0; i < n; i++) a[i] = a_[i];

    set<int> visited;
    for (int i = 0; i < n; i++) {
        if (visited.count(a[i])) return 0;
        visited.insert(a[i]);
    }

    int start = -1;
    for (int i = 0; i < n; i++) {
        if (a[i] <= n) {
            start = i - a[i] + 1;
            if (start < 0) start += n;
            break;
        }
    }
    if (start == -1) return 0;

    rotate(a.begin(), a.begin()+start, a.end());
    for (int i = 0; i < n;  i++) {
        if (a[i] <= n && a[i] != i+1) return 0;
    }

    return 1;
}

int replacement(int n, int a_[], int b[]) {
    vi a(n), orig(n);
    int mxi = 0, start = 0;
    for (int i = 0; i < n; i++) {
        a[i] = a_[i];
        if (a[i] > a[mxi]) mxi = i;
        if (a[i] <= n) start = (i-a[i]+1 + n)%n;
        orig[i] = i+1;
    }
    rotate(orig.begin(), orig.begin()+(n-start), orig.end());

    int off = (n+1);
    memset(b, -1, sizeof(int) * (a[mxi] - n));
    for (int i = 0; i < n; i++) {
        if (a[i] != orig[i]) b[a[i]-off] = orig[i];
    }
    int spare = orig[mxi];
    for (int i = n+1; i <= a[mxi]; i++) {
        if (b[i-off] == -1) {
            b[i-off] = spare;
            spare = i;
        }
    }
    b[a[mxi]-off] = spare;
    return a[mxi] - n;
}

ll modpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b&1) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

int countReplacement(int n, int inputSeq[]) {
    vi a(n);
    for (int i = 0; i < n; i++) a[i] = inputSeq[i];
    sort(a.begin(), a.end());
    ll res = 1;
    int i = lower_bound(a.begin(), a.end(), n+1) - a.begin();
    for (; i < n; i++) {
        int remain = n - i;
        res = res * modpow(remain, a[i] - 1 - max(n, i?a[i-1]:0)) % MOD;;
        debug(a, i, res);
    }
    return res;
}

Compilation message (stderr)

gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:8:24: warning: statement has no effect [-Wunused-value]
    8 |     #define debug(...) 42
      |                        ^~
gondola.cpp:103:9: note: in expansion of macro 'debug'
  103 |         debug(a, i, res);
      |         ^~~~~
#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...