Submission #309316

#TimeUsernameProblemLanguageResultExecution timeMemory
309316jainbot27곤돌라 (IOI14_gondola)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
#define int long long

#define f first
#define s second
#define pb push_back
#define ar array
#define all(x) x.begin(), x.end()
#define siz(x) (int)x.size()

#define FOR(x, y, z) for(int x = (y); x < (z); x++)
#define ROF(x, z, y) for(int x = (y-1); x >= (z); x--)
#define F0R(x, z) FOR(x, 0, z)
#define R0F(x, z) ROF(x, 0, z)
#define trav(x, y) for(auto&x:y)

using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;

template<class T> inline bool ckmin(T&a, T b) {return b < a ? a = b, 1 : 0;}
template<class T> inline bool ckmax(T&a, T b) {return b > a ? a = b, 1 : 0;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const char nl = '\n';
const int mxN = 1e5 + 10;
const int MOD = 1e9 + 9;
const long long infLL = 1e18;

int valid(int n, int* _inputSeq){
    vi inputSeq(n);
    F0R(i, n){
        inputSeq[i] = _inputSeq[i];
        inputSeq[i]--;
    }
    vi vals;
    F0R(i, n){
        vals.pb(inputSeq[i]);
    }
    sort(all(vals));
    vals.resize(unique(all(vals))-vals.begin());
    if(siz(vals)!=n) return 0;
    if(vals[0]>=n) return 1;
    int pos;
    F0R(i, n){
        if(inputSeq[i] < n){
            pos = i;
            break;
        }
    }
    int ff = inputSeq[pos];
    F0R(i, n){
        if(inputSeq[i]<=n){
            int dif = i - pos;
            int should = (n + ff + dif)%n;
            if(inputSeq[i] != should) return 0;
        }
    }
    return 1;
}

int replacement(int n, int _gondolaSeq[], int _replacementSeq[]){
    vi gs(n), rs;
    F0R(i, n){
        gs[i] = _gondolaSeq[i]-1;
    }
    int pos = 0, cnt = 0, mx = -1, sp, mxpos; 
    sp = 0;
    map<int, int> vals;
    F0R(i, n){
        if(ckmax(mx, gs[i])) mxpos = i;
        if(gs[i] < n){
            pos = i; 
            sp = gs[i];
            cnt++;
        }
    }
    if(cnt==n){
        return 0;
    }
    // cout << pos << " " <<  sp << endl;
    int foo;
    F0R(i, n){
        int dif = i - pos;
        int should=  (n + sp + dif) % n;
        // cout << i << " " << should << endl;
        if(mxpos==i){
            foo = should;
        }
        if(gs[i]<n&&gs[i]!=should) 
            assert(false);
        if(gs[i]==should)
            continue;
        vals[gs[i]]=should;     
    }
    int x = 0;
    // cout << mx << endl;
    FOR(i, n, mx+1){
        if(vals.find(i)!=vals.end()&&i!=mx){
            // cout << i << " " << vals[i] << endl;
            _replacementSeq[x] = vals[i]+1;
            x++;
            continue;
        }
        _replacementSeq[x] = foo+1;
        foo=i;
        x++;
        // cout<<i<<endl;
    }
    return x;
}
// modulo class
int fact[mxN];
int add(int x, int y){ x += y; while(x >= MOD) x -= MOD; while(x < 0) x += MOD; return x; } void ad(int &x, int y) {x = add(x, y);}
int sub(int x, int y){ x -= y; while(x >= MOD) x -= MOD; while(x < 0) x += MOD; return x; } void sb(int &x, int y) {x = sub(x, y);}
int mul(int x, int y){ return ((int64_t)x * (int64_t)y) % MOD; } void ml(int &x, int y) {x = mul(x, y);}
int binpow(int x, int y){ int z = 1; while(y > 0) { if(y % 2 == 1) z = mul(z, x); x = mul(x, x); y /= 2; } return z; }
int inv(int x){ return binpow(x, MOD - 2); }
int divide(int x, int y){ return mul(x, inv(y)); }
void precalc(){ fact[0] = 1; for(int i = 1; i < mxN; i++) fact[i] = mul(i, fact[i - 1]); }
int choose(int n, int k){ if(k > n) return 0; return divide(fact[n], mul(fact[n - k], fact[k])); }

int countReplacement(int n, int inputSeq[]){
    if(!valid(n, inputSeq)) return 0;
    vi gs(n);
    F0R(i, n){
        gs[i] = inputSeq[i]-1;
    }
    int pos = 0, cnt = 0, mx = -1, sp, mxpos; 
    sp = 0;
    map<int, int> vals;
    F0R(i, n){
        if(gs[i] < n){
            pos = i; 
            sp = gs[i];
            cnt++;
        }
    }
    if(cnt==n){
        return 1;
    }
    // cout << pos << " " <<  sp << endl;
    int foo;
    int res = 1;
    int bruh = 0;
    F0R(i, n){
        int dif = i - pos;
        int should=  (n + sp + dif) % n;
        if(gs[i]==should)
            continue;
        vals[gs[i]]=should;     
        bruh++;
    }
    int amt = bruh;
    // cout << mx << endl;
    FOR(i, n, mx+1){
        if(vals.find(i)!=vals.end()){
            // cout << i << " " << vals[i] << endl;
            amt--;
            continue;
        }
        ml(res, amt);
        // cout<<i<<endl;
    }
    if(cnt == 0){
        return mul(res, n);
    }
    return res;
}

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

    int gondolaSeq[] = {2, 3, 4, 12, 6, 7, 1};
    int n = 7;
    int ans =countReplacement(n, gondolaSeq);
    cout << ans << nl;
    return 0;
}

Compilation message (stderr)

gondola.cpp: In function 'long long int countReplacement(long long int, long long int*)':
gondola.cpp:133:40: warning: unused variable 'mxpos' [-Wunused-variable]
  133 |     int pos = 0, cnt = 0, mx = -1, sp, mxpos;
      |                                        ^~~~~
gondola.cpp:147:9: warning: unused variable 'foo' [-Wunused-variable]
  147 |     int foo;
      |         ^~~
gondola.cpp: In function 'long long int replacement(long long int, long long int*, long long int*)':
gondola.cpp:109:33: warning: 'foo' may be used uninitialized in this function [-Wmaybe-uninitialized]
  109 |         _replacementSeq[x] = foo+1;
      |                              ~~~^~
gondola.cpp:91:9: warning: 'mxpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   91 |         if(mxpos==i){
      |         ^~
gondola.cpp: In function 'long long int valid(long long int, long long int*)':
gondola.cpp:48:9: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |     int pos;
      |         ^~~
/tmp/ccqwt7wt.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cchmLUrX.o:gondola.cpp:(.text.startup+0x0): first defined here
/tmp/ccqwt7wt.o: In function `main':
grader.cpp:(.text.startup+0xa2): undefined reference to `valid'
grader.cpp:(.text.startup+0xee): undefined reference to `countReplacement'
grader.cpp:(.text.startup+0x112): undefined reference to `replacement'
collect2: error: ld returned 1 exit status