Submission #584800

#TimeUsernameProblemLanguageResultExecution timeMemory
584800BelguteiGondola (IOI14_gondola)C++17
5 / 100
3 ms468 KiB
#include "gondola.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define MOD 1000000007
#define MOD1 1000000009

map<int,int> mp;
map<int,int> :: iterator it;

int valid(int n, int inputSeq[]) {
  // mp.clear();
  // int pos = -1;
  // for(int i = 0; i < n; i ++) {
  //   if(inputSeq[i] <= n) {
  //     pos = i;
  //   }
  //   mp[inputSeq[i]] ++;
  // }
  // for(it = mp.begin(); it != mp.end(); it ++) {
  //   if(it -> ss > 1) {
  //     return 0;
  //   }
  // }
  // if(pos == -1) return 1;
  // int val = inputSeq[pos];
  // for(int i = pos + 1; i < n; i ++) {
  //   val ++;
  //   if(val == n + 1) val = 1;
  //   if(inputSeq[i] <= n && inputSeq[i] != val) return 0;
  // }
  // for(int i = 0; i < pos; i ++) {
  //   val ++;
  //   if(val == n + 1) val = 1;
  //   if(inputSeq[i] <= n && inputSeq[i] != val) return 0;
  // }
  // //
  // return 1;
}

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

int replacement(int n, int gondolaSeq[], int replacementSeq[]) {
  mp.clear();
  int pos = -1, tmp_pos = -1;
  int cnt = 0, mx = 0;
  for(int i = 0; i < n; i ++) {
    if(gondolaSeq[i] <= n) {
      pos = i;
    }
    else {
      if (mx < gondolaSeq[i]) {
        tmp_pos = i;
        mx = gondolaSeq[i];
      }
    }
    mp[gondolaSeq[i]] ++;
  }
  //
  if(tmp_pos == -1) return 0;
  if(pos == -1) {
    for(;;);
    int ans = 0;
    for(int i = mx - 1; i >= 1; i --) {
      if(mp[i] == 0) {
        replacementSeq[ans] = i;
        ans ++;
      }
    }
    return ans;
  }
  int val = gondolaSeq[pos];
  int ans = 0;
  int target_val;
  //
  for(int i = pos + 1; i < n; i ++) {
    val ++;
    if(val == n + 1) val = 1;
    if(tmp_pos == i) {
      target_val = val;
      continue;
    }
    if(gondolaSeq[i] > n) {
      replacementSeq[ans] = val;
      ans ++;
    }
  }
  //
  for(int i = 0; i < pos; i ++) {
    val ++;
    if(val == n + 1) val = 1;
    if(tmp_pos == i) {
      target_val = val;
      continue;
    }
    if(gondolaSeq[i] > n) {
      replacementSeq[ans] = val;
      ans ++;
    }
  }
  //
  for(int i = gondolaSeq[tmp_pos] - 1; i > n; i --) {
    if(mp[i] == 0) {
      replacementSeq[ans] = i;
      ans ++;
    }
  }
  replacementSeq[ans] = target_val;
  ans ++;
  return ans;
}

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

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

Compilation message (stderr)

gondola.cpp: In function 'int valid(int, int*)':
gondola.cpp:45:1: warning: no return statement in function returning non-void [-Wreturn-type]
   45 | }
      | ^
gondola.cpp: In function 'int replacement(int, int*, int*)':
gondola.cpp:52:7: warning: unused variable 'cnt' [-Wunused-variable]
   52 |   int cnt = 0, mx = 0;
      |       ^~~
gondola.cpp:114:23: warning: 'target_val' may be used uninitialized in this function [-Wmaybe-uninitialized]
  114 |   replacementSeq[ans] = target_val;
      |   ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#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...