Submission #309516

# Submission time Handle Problem Language Result Execution time Memory
309516 2020-10-03T17:52:18 Z jainbot27 Gondola (IOI14_gondola) C++17
100 / 100
35 ms 2800 KB
#include <bits/stdc++.h>
#include "gondola.h"
using namespace std;
 
#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 = 1'000'000'009;
const long long infLL = 1e18;
 
int32_t 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;
}
int32_t 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;
    }
    int foo;
    F0R(i, n){
        int dif = i - pos;
        int should=  (n + sp + dif) % n;
        if(mxpos==i){
            foo = should;
        }
        if(gs[i]==should)
            continue;
        vals[gs[i]]=should;     
    }
    int x = 0;
    FOR(i, n, mx+1){
        if(vals.find(i)!=vals.end()&&i!=mx){
            _replacementSeq[x] = vals[i]+1;
            x++;
            continue;
        }
        _replacementSeq[x] = foo+1;
        foo=i;
        x++;
    }
    return x;
}
// modulo class
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; }
 
int32_t countReplacement(int n, int inputSeq[]){
    if(!valid(n, inputSeq)) return 0;
    int res = 1;
    sort(inputSeq, inputSeq+n);
    bool f = 1;
    F0R(i, n){
        if(inputSeq[i]>n){
            if(f){
                ml(res, binpow(n-i, inputSeq[i]-n-1));
            }
            else{
                ml(res, binpow(n-i, inputSeq[i]-inputSeq[i-1]-1));
            }
            f = 0;
        }
    }
    if(inputSeq[0]>n) ml(res, n);
    return res;
}

Compilation message

gondola.cpp: In function 'int32_t replacement(int, int*, int*)':
gondola.cpp:101:33: warning: 'foo' may be used uninitialized in this function [-Wmaybe-uninitialized]
  101 |         _replacementSeq[x] = foo+1;
      |                              ~~~^~
gondola.cpp:87:9: warning: 'mxpos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |         if(mxpos==i){
      |         ^~
gondola.cpp: In function 'int32_t valid(int, int*)':
gondola.cpp:47:9: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |     int pos;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 9 ms 1280 KB Output is correct
7 Correct 22 ms 2164 KB Output is correct
8 Correct 14 ms 1916 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 20 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 9 ms 1280 KB Output is correct
7 Correct 21 ms 2172 KB Output is correct
8 Correct 14 ms 1916 KB Output is correct
9 Correct 6 ms 896 KB Output is correct
10 Correct 22 ms 2172 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 9 ms 1280 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 21 ms 2172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 416 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1408 KB Output is correct
12 Correct 13 ms 1536 KB Output is correct
13 Correct 31 ms 2800 KB Output is correct
14 Correct 12 ms 1408 KB Output is correct
15 Correct 33 ms 2336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 25 ms 2076 KB Output is correct
10 Correct 20 ms 1536 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 9 ms 916 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 25 ms 2044 KB Output is correct
10 Correct 20 ms 1536 KB Output is correct
11 Correct 8 ms 896 KB Output is correct
12 Correct 9 ms 916 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 31 ms 2172 KB Output is correct
15 Correct 35 ms 2296 KB Output is correct
16 Correct 7 ms 896 KB Output is correct
17 Correct 23 ms 1696 KB Output is correct
18 Correct 13 ms 1408 KB Output is correct