Submission #297796

#TimeUsernameProblemLanguageResultExecution timeMemory
297796juckterGondola (IOI14_gondola)C++14
55 / 100
36 ms4728 KiB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int MAXV = 3e5 + 10;


int valid(int n, int inputSeq[]) {
    set<int> seen;
    int rot = -1;
    for(int i = 0; i < n; i++) {
        if(seen.count(inputSeq[i]))
            return 0;
        seen.insert(inputSeq[i]);
        if(inputSeq[i] <= n) {
            int nr = (inputSeq[i] - i + n) % n;
            if(rot != -1 && rot != nr)
                return 0;
            rot = nr;
        }
    }
    return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
    if(*min_element(gondolaSeq, gondolaSeq + n) <= n) {
        int rot;

        for(int i = 0; i < n; i++)
            if(gondolaSeq[i] <= n)
                rot = (gondolaSeq[i] - i + n - 1) % n;

        rotate(gondolaSeq, gondolaSeq + (n - rot) % n, gondolaSeq + n);
    }
    //for(int i = 0; i < n; i++)
    //    cerr << gondolaSeq[i] << " ";
    //cerr << '\n';
    int mx = *max_element(gondolaSeq, gondolaSeq + n);
    int mpos = -1;
    vector<int> pos(300000);
    for(int i = 0; i < n; i++) {
        pos[gondolaSeq[i]] = i + 1;
        if(gondolaSeq[i] == mx)
            mpos = i;
    }
    int st = 0, len = mx - n;
    int pv = mpos + 1;
    for(int i = n + 1; i <= mx; i++) {
        if(i != mx && pos[i])
            replacementSeq[st++] = pos[i];
        else {
            replacementSeq[st++] = pv;
            pv = i;
        }
    }
    return len;

    return len;
}

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

int countReplacement(int n, int inputSeq[]) {
    return -3;
}

Compilation message (stderr)

gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:36:44: warning: 'rot' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |         rotate(gondolaSeq, gondolaSeq + (n - rot) % n, gondolaSeq + 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...