Submission #1186015

#TimeUsernameProblemLanguageResultExecution timeMemory
1186015swishy123Gondola (IOI14_gondola)C++20
Compilation error
0 ms0 KiB
#include <iostream>
#include <algorithm>
#include <vector>
#include <random>
#include <chrono>
#include <set>
#include <map>
#include <stack>
#include <functional>
#include <iomanip>
#include <queue>
#include <cassert>
#include <complex>
#include <cstring>
#include <memory>
#include <bitset>
#include <sstream>
#include <cmath>
#include <numeric>
#include <numbers>
#include <fstream>
#include "gondola.h"

using namespace std;

#ifndef template
#ifndef define
 
#define ll long long
#define ld long double
#define pl pair<ll, ll>
#define pi pair<int, int>
#define nl cout << '\n';
#define x first
#define y second 
#define cbit(x) __builtin_popcountll(x)
#define uid(a, b) uniform_int_distribution<ll>(a, b)(rng) 
#define siz(x) (int)x.size()
 
#endif
 
#ifndef print
void print(size_t x) {cout << x << ' ';}
void print(int x) {cout << x << ' ';}
void print(long long x) {cout << x << ' ';}
void print(float x) {cout << x << ' ';}
void print(long double x) {cout << x << ' ';}
void print(char x) {cout << x << ' ';}
void print(const char* x) {cout << x << ' ';}
void print(bool x) {cout << x << ' ';}
void print(string &x) {cout << x << ' ';}
 
template<typename T, typename V>
void print(pair<T, V> &p) {print(p.x); print(p.y);}
template<typename T>
void print(vector<T> v) {for (int i = 0; i < v.size(); i++) print(v[i]);}
template<typename T>
void print(vector<vector<T>> v) {
    for (int i = 0; i < v.size(); i++){
        for (int j = 0; j < v[i].size(); j++)
            print(v[i][j]);
        nl;
    }
}
template <typename T, typename... V>
void print(T t, V&&... v) {print(t); print(v...);}
 
#endif
 
#ifndef read
void read(int &x) {cin >> x;}
void read(long long &x) {cin >> x;}
void read(unsigned &x) {cin >> x;}
void read(unsigned long long &x) {cin >> x;}
void read(float &x) {cin >> x;}
void read(long double &x) {cin >> x;}
void read(char &x) {cin >> x;}
void read(string &x) {cin >> x;}
void read(bool &x) {cin >> x;}
 
template<typename T> 
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++)
        read(v[i]);
}
template <typename T, typename... V>
void read(T &t, V&... v) {read(t); read(v...);}
#endif
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> bool maxi(T& a, const T& b) {
    return a < b ? a = b, 1 : 0;
}
template<class T> bool mini(T& a, const T& b) {
    return a > b ? a = b, 1 : 0;
}
template<class... Args>
auto vec(size_t n, Args&&... args) {
    if constexpr(sizeof...(args) == 1)
        return vector(n, args...);
    else
        return vector(n, vec(args...));
}

#endif

using namespace std;
const ll inf = 1e18;
const ll def = 1e6+1;
const ll mod = 1e9+9;

using namespace std;

ll powmod(ll a, ll b){
    if (b == 0)
        return 1;
    if (b % 2 == 0){
        ll val = powmod(a, b / 2);
        return (val * val) % mod;
    }
    else
        return (powmod(a, b - 1) * a) % mod;
}

int valid(int n, int inputSeq[]){
    int anchor = -1;
    bool res = 1;

    map<int, int> mp;
    for (int i = 0; i < n; i++){
        mp[inputSeq[i]]++;
        if (mp[inputSeq[i]] > 1)
            return 0;
        if (inputSeq[i] <= n){
            int val = (i - inputSeq[i] + 1 + n) % n;
            if (anchor == -1)
                anchor = val;
            else{
                if (anchor != val)
                    res = 0;
            }
        }
    }
    return res;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]){
    vector<int> pos;
    int anchor = 0;

    map<int, int> need;
    for (int i = 0; i < n; i++){
        if (gondolaSeq[i] <= n){
            int val = (i - gondolaSeq[i] + 1 + n) % n;
            anchor = val;
        }
        else
            need[gondolaSeq[i]] = i;
    }
    auto org = vec(n, 0);
    int j = anchor;
    for (int i = 0; i < n; i++){
        org[j] = i + 1;
        (j += 1) %= n;
    }
    set<int> s;
    for (int i = 0; i < n; i++){
        if (org[i] != gondolaSeq[i])
            s.insert(i);
    }
    int crr = n + 1;
    while (s.size()){
        int nxt;
        if (need.count(crr))    
            nxt = need[crr];
        else    
            nxt = *s.begin();
        replacementSeq[crr - n - 1] = org[nxt];
        org[nxt] = crr;
        s.erase(nxt);
        if (org[nxt] != gondolaSeq[nxt])
            s.insert(nxt);
        crr++;
    }
    return crr - n - 1;
}

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

int countReplacement(int n, int inputSeq[]){
    if (!valid(n, inputSeq))
        return 0;
    vector<int> order;
    for (int i = 0; i < n; i++){
        if (inputSeq[i] > n)
            order.push_back(inputSeq[i]);
    }
    sort(order.begin(), order.end());
    ll res = 1, last = n + 1;

    for (int i = 0; i < order.size(); i++){
        (res *= powmod(order.size() - i, order[i] - last)) %= mod;
        last = order[i] + 1;
    }
    return res;
}

int gondolaSequence[100001];
int replacementSequence[250001];

void solve(){
    int i, n, tag;
    int nr; 
    assert(scanf("%d", &tag)==1);
    assert(scanf("%d", &n)==1);
    for (i = 0; i < n; i++)
        assert( scanf("%d", &gondolaSequence[i]) ==1);
    
    switch (tag){
    case 1: case 2: case 3:
        printf("%d\n", valid(n, gondolaSequence));
        break;
  
    case 4: case 5: case 6:
        nr = replacement(n, gondolaSequence, replacementSequence);
        printf("%d ", nr);
        if (nr > 0){
            for (i = 0; i < nr - 1; i++)
                printf("%d ", replacementSequence[i]);
            printf("%d\n", replacementSequence[nr-1]);
        }  
        else 
            printf("\n");
        break;
  
    case 7: case 8: case 9: case 10:
        printf("%d\n",  countReplacement(n, gondolaSequence));  
        break;
    }
}

// int32_t main(){
//     ios_base::sync_with_stdio(0);
//     cin.tie(0); cout.tie(0);

//     if (ifstream("input.txt").good()){
//         freopen("input.txt", "r", stdin);
//         freopen("output.txt", "w", stdout);
//     }

//     int t = 1;
//     while (t--){
//         solve();
//         nl;
//     }

//     return 0;
// }

Compilation message (stderr)

/usr/bin/ld: /tmp/cc4Eh5rZ.o:(.bss+0xf4260): multiple definition of `gondolaSequence'; /tmp/ccNxeX6y.o:(.bss+0xf4260): first defined here
/usr/bin/ld: /tmp/cc4Eh5rZ.o:(.bss+0x0): multiple definition of `replacementSequence'; /tmp/ccNxeX6y.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status