Submission #1220613

#TimeUsernameProblemLanguageResultExecution timeMemory
1220613kunzaZa183Gondola (IOI14_gondola)C++20
25 / 100
28 ms4680 KiB
#include "gondola.h"
#include <bits/stdc++.h>
using namespace std;

int valid(int n, int inputSeq[]) {
  map<int, int> mii;
  for (int i = 0; i < n; i++)
    mii[inputSeq[i]]++;

  for (auto a : mii)
    if (a.second >= 2)
      return 0;

  int in = min_element(inputSeq, inputSeq + n) - inputSeq;

  if (in > n)
    return 1;

  int cur = inputSeq[in];
  for (int i = in; i < n; i++) {
    if (inputSeq[i] <= n && inputSeq[i] != cur)
      return 0;
    cur++;
    cur %= n;
  }

  return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
  int in = min_element(gondolaSeq, gondolaSeq + n) - gondolaSeq;

  vector<int> rep(n, -1);

  if (in <= n) {
    int cur = gondolaSeq[in];
    for (int i = in; i < n; i++) {
      if (gondolaSeq[i] > n)
        rep[cur] = gondolaSeq[i];
      cur++;
      cur %= n;
    }

    for (int i = 0; i < in; i++) {
      if (gondolaSeq[i] > n)
        rep[cur] = gondolaSeq[i];
      cur++;
      cur %= n;
    }
  } else {
    for (int i = 0; i < n; i++)
      rep[i] = gondolaSeq[i];
  }

  vector<pair<int, int>> vpii;
  for (int i = 0; i < n; i++) {
    if (rep[i] != -1)
      vpii.emplace_back(rep[i], i == 0 ? n : i);
  }

  sort(vpii.begin(), vpii.end());
  int cur = n + 1;

  int len = 0;

  for (auto a : vpii) {
    replacementSeq[len++] = a.second;
    for (int i = cur; i < a.first; i++)
      replacementSeq[len++] = i;

    cur = a.first + 1;
  }

  return len;
}

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

int countReplacement(int n, int inputSeq[]) { return -3; }
#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...