Submission #1267121

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

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 {
    // Subtask 3
    std::vector<int> cnt(N, 0);
    std::vector<int> price(N, 0);

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

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

      if (res.second == 0 && res.first.size() == 1) {
        price[res.first[0]] = current_price;

        if (first_price == -1) {
          first_price = current_price;
        }
      }
    }

    int increment = 1;
    if (price[N-1] == 1) {
      increment = 2;
    }

    for(int current_price = first_price+increment; price[1] == 0 ; current_price+= increment) {
      std::pair<std::vector<int>, long long> res = transaction(current_price);

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

      if (res.second == 0 && res.first.size() == 1) {
        price[res.first[0]] = current_price;
      }
    }

    for (int i=1; i<N; i++) {
      for (int j = cnt[i]; j < i; j++) {
        transaction(price[i]);
      }
    }
  }
}
#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...