Submission #589379

#TimeUsernameProblemLanguageResultExecution timeMemory
589379Do_you_copyGondola (IOI14_gondola)C++14
60 / 100
20 ms3240 KiB
#include <bits/stdc++.h>
#include <gondola.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

const ll Mod = 1000000007;
const ll Mod2 = 999999999989;
const int maxN = 25e4 + 1;
int mp[maxN];
int n;

ll power(int x, int y){
    if (y == 0) return 1;
    if (y == 1) return x;
    ll t = power(x, y / 2);
    if (y % 2) return t * t % Mod * x % Mod;
    else return t * t % Mod;
}

int valid(int N, int inputSeq[]){
    n = N;
    int pivot, cnt = 0, tem = INT_MAX;
    for (int i = 0; i < n; ++i){
        if (mp[inputSeq[i]]) return 0;
        mp[inputSeq[i]] = 1;
        if (inputSeq[i] > n) ++cnt;
        if (tem > inputSeq[i]){
            tem = inputSeq[i];
            pivot = i;
        }
    }
    if (cnt == n) return 1;
    //pivot is where the number one is supposed to be at
    pivot = ((pivot - tem + 1) + n) % n;
    for (int i = pivot; i < pivot + n; ++i){
        if (inputSeq[i % n] <= n && inputSeq[i % n] != i - pivot + 1){
            return 0;
        }
    }
    return 1;
}

int replacement(int N, int gondolaSeq[], int replacementSeq[]){
    n = N;
    int pivot = n - 1, tem = n, maxx = 0;
    for (int i = 0; i < n; ++i){
        if (tem > gondolaSeq[i]){
            tem = gondolaSeq[i];
            pivot = i;
        }
        maxx = max(maxx, gondolaSeq[i]);
        mp[gondolaSeq[i]] = i + 1;
    }
    pivot = ((pivot - tem + 1) + n) % n;
    vector <int> a(n);
    vector <int> b;
    for (int i = n + 1; i <= maxx; ++i){
        if (!mp[i]) b.pb(i);
    }
    for (int i = pivot; i < pivot + n; ++i){
        a[i % n] = i - pivot + 1;
    }
    vector <int> ans;
    while (!b.empty()){
        int k = b.back();
        b.pop_back();
        ans.pb(k);
        gondolaSeq[mp[maxx] - 1] = k;
        mp[k] = mp[maxx];
        --maxx;
    }
    while (maxx > n){
        int k = a[mp[maxx] - 1];
        ans.pb(k);
        //gondolaSeq[mp[maxx] - 1] = k;
        --maxx;
    }
    for (int i = 0; i < ans.size(); ++i) replacementSeq[i] = ans[ans.size() - i - 1];
    return ans.size();
}

int countReplacement(int N, int inputSeq[]){
    n = N;
    int pivot, cnt = 0, tem = INT_MAX;
    map <int, int> mp;
    vector <int> a;
    ll ans = 1;
    for (int i = 0; i < n; ++i){
        if (mp[inputSeq[i]]) return 0;
        mp[inputSeq[i]] = 1;
        if (inputSeq[i] > n){
            ++cnt;
            a.pb(inputSeq[i]);
        }
        if (tem > inputSeq[i]){
            tem = inputSeq[i];
            pivot = i;
        }
    }
    if (cnt == n){
        ans = n;
    }
    //pivot is where the number one is supposed to be at
    pivot = ((pivot - tem + 1) + n) % n;
    for (int i = pivot; i < pivot + n; ++i){
        if (inputSeq[i % n] <= n && inputSeq[i % n] != i - pivot + 1){
            return 0;
        }
    }
    sort(a.begin(), a.end());
    int last = n;
    for (int i = 0; i < a.size(); ++i){
        ans = ans * power(a.size() - i, a[i] - last - 1) % Mod;
        last = a[i];
    }
    return ans;
}

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:97:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for (int i = 0; i < ans.size(); ++i) replacementSeq[i] = ans[ans.size() - i - 1];
      |                     ~~^~~~~~~~~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:131:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  131 |     for (int i = 0; i < a.size(); ++i){
      |                     ~~^~~~~~~~~~
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:53:21: warning: 'pivot' may be used uninitialized in this function [-Wmaybe-uninitialized]
   53 |     pivot = ((pivot - tem + 1) + n) % n;
      |               ~~~~~~^~~~~
gondola.cpp: In function 'int countReplacement(int, int*)':
gondola.cpp:123:21: warning: 'pivot' may be used uninitialized in this function [-Wmaybe-uninitialized]
  123 |     pivot = ((pivot - tem + 1) + n) % n;
      |               ~~~~~~^~~~~
#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...