Submission #589367

#TimeUsernameProblemLanguageResultExecution timeMemory
589367Do_you_copyGondola (IOI14_gondola)C++14
55 / 100
21 ms3308 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;

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[]){
    if (!valid(N, inputSeq)) return 0;
}


Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:89:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |     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:94:1: warning: control reaches end of non-void function [-Wreturn-type]
   94 | }
      | ^
gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:45:21: warning: 'pivot' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |     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...