Submission #1262502

#TimeUsernameProblemLanguageResultExecution timeMemory
1262502abdelhakimSouvenirs (IOI25_souvenirs)C++20
0 / 100
0 ms412 KiB
#include "souvenirs.h"
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cerr<<#x << ' ' << x << endl;
using namespace std;
ll n;
vector<ll> value;
vector<ll> cnt;
void printvec(vector<ll>& v)
{
  for (auto &&e : v)
  {
    cout << e << ' ' ;
  }
  cout << endl; 
}
void gad(vector<int>& v)
{
  for (auto &&e : v)
  {
    cnt[e]++;
  }
}
void buy_souvenirs(int N, long long P0) {
  // std::pair<std::vector<int>, long long> res = transaction(3);
  n=N;
  value.resize(n);
  cnt.resize(n);
  value[0]=P0;
  ll j=0;
  while(j<n-1)
  {
    ll val=value[j]/2;
    if(j==n-2) val=value[j]-1;
    pair<vector<int>,ll> res = transaction(val);
    gad(res.first);
    j=res.first[0];
    value[j]=val-res.second;
  }
  map<ll,pair<ll,ll>> mp;
  pair<vector<int>,ll> res1 = transaction(P0-1);
  gad(res1.first);
  mp[1]={P0-1-res1.second,res1.first.size()};
  if(res1.first.size()==1)
  {
    value[1]=P0-1-res1.second;
  }
  for (int i=n-1;i>=1;i--)
  {
    if(value[i]==0)
    {
      for (int j=i;j>=0;j--)
      {
        ll val=0;
        if(mp[j].first!=0)
        {
          val=mp[j].first/mp[j].second;
          if(mp[j].second==1)
          {
            val=mp[j].first-1;
          }
          break;
        }
        while(value[i]==0)
        {
          pair<vector<int>,ll> res = transaction(val);
          vector<ll> v;
          ll sm=val-res.second;
          for (auto &&e : res.first)
          {
            sm-=value[e];
            if(value[e]==0)
            {
              v.push_back(e);
            }
          }
          mp[v[0]]={sm,v.size()};
          if(v.size()==1)
          {
            value[v[0]]=sm;
          }
          gad(res.first);
          val=sm/v.size();
        }
      }
    }
  }
  for (int i=1;i<n;i++)
  {
    while(cnt[i]<i)
    {
      pair<vector<int>,ll> res = transaction(value[i]);
      cnt[i]++;
    }
  }
  return;
}
#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...