Submission #1268657

#TimeUsernameProblemLanguageResultExecution timeMemory
1268657strange420Souvenirs (IOI25_souvenirs)C++20
25 / 100
11 ms408 KiB
#include "souvenirs.h"
#include <utility>
#include <vector>
#include <iostream>

void subtask3(int N, long long P0) {
  // Subtask 3
  std::vector<int> cnt(N, 0);
  std::vector<int> price(N, 0);

  long long current_price = P0 - 1;
  while (price[N-1] == 0) {
    std::pair<std::vector<int>, long long> res = transaction(current_price);

    for (auto x: res.first) {
      cnt[x]++;
    }

    if (res.first.size() == 1 && res.second == 0) {
      int i = res.first[0];
      price[i] = current_price;
      current_price --;
    } else {
      int i = res.first[0];
      price[i] = current_price - 1;
      current_price -= 2;
    }
  }

  for (int i=1; i<N; i++) {
    for (int j = cnt[i]; j < i; j++) {
      transaction(price[i]);
    }
  }
}

void subtask5(int N, long long P0) {
  // Subtask 5
  std::vector<int> cnt(N, 0);
  std::vector<int> price(N, 0);

  long long current_price = P0 - 1;
  for (int i=1; price[N-1] == 0; i++) {
    std::pair<std::vector<int>, long long> res = transaction(current_price);
    for (auto x: res.first) {
      cnt[x]++;
    }
    while (cnt[i]<i) {
      transaction(current_price);
      cnt[i]++;
    }

    if (res.second == 0 && res.first.size() == 1 && res.first[0] == i) {
      current_price--;
    } else {
      current_price = (current_price - res.second)/2;
    }
  }
}

void buy_souvenirs(int N, long long P0) {
  if (N == 2) {
    // Subtask 1
    transaction(P0 - 1);
  } else if (P0 == N) {
    // Subtask 2
    for (long long i = N-1, k = 1; i>0; i--, k++) {
      for (int j = 0; j < k; j++) {
        transaction(i);
      }
    }
  } else if (N == 3) {
    // Subtask 4
    std::pair<std::vector<int>, long long> res = transaction(P0-1);
    long long price = P0-1-res.second;
    if (res.first.size() == 1) {
      transaction(price-1);
      transaction(price-1);
    } else {
      long long special = price / 2;
      transaction(special);
    }
  } else {
    subtask5(N, P0);
  }
}
#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...