제출 #1252907

#제출 시각아이디문제언어결과실행 시간메모리
1252907Giselus선물 (IOI25_souvenirs)C++20
39 / 100
1071 ms424 KiB
#include <bits/stdc++.h>
#include "souvenirs.h"
using namespace std;
#define fwd(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) fwd(i, 0, n)
#define all(X) X.begin(), X.end()
#define sz(X) int(size(X))
#define pb push_back
#define eb emplace_back
#define st first
#define nd second
using pii = pair<int, int>; using vi = vector<int>;
using ll = long long; using ld = long double;
#ifdef LOC
auto SS = signal(6, [](int) { *(int *)0 = 0; });
#define DTP(x, y) auto operator << (auto &o, auto a) -> decltype(y, o) { o << "("; x; return o << ")"; }
DTP(o << a.st << ", " << a.nd, a.nd);
DTP(for (auto i : a) o << i << ", ", all(a));
void dump(auto... x) { (( cerr << x << ", " ), ...) << '\n'; }
#define deb(x...) cerr << setw(4) << __LINE__ << ":[" #x "]: ", dump(x)
#else
#define deb(...) 0
#endif

#define S 107

// pair<vi, ll> transaction(ll M);

ll P[S];
int how_many[S];

void f(int k, ll p) {
    if(P[k])
        return;
    
    auto e = transaction(p);
    for(auto v: e.st) how_many[v]++;
    p -= e.nd;

    while(1) {
        vi tmp;
        for(auto v: e.st) {
            if(P[v])
                p -= P[v];
            else
                tmp.pb(v);
        }
        e.st = tmp;
        if (e.st.size() == 1) {
            P[e.st[0]] = p;
            if(e.st[0] != k)
                f(e.st[0]+1, p-1);
            return;   
        } 
        f(e.st[1], (p-1)/2);
    }
}

void buy_souvenirs(int n, ll P0) {
    P[0] = P0;
    for(int i = 1; i <= n-1; i++) {
        if(P[i])
            continue;    
        f(i, P[i-1]-1);
    }

    for(int i = 1; i <= n-1; i++) {
        while(how_many[i] < i) {
            how_many[i]++;
            transaction(P[i]);
        }
    }
}

// int32_t main() {
// 	cin.tie(0)->sync_with_stdio(0);
// 	cout << fixed << setprecision(10);

// }
#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...