| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 1285834 | dimitri.shengelia | Souvenirs (IOI25_souvenirs) | C++20 | 0 ms | 0 KiB | 
#include "souvenirs.h"
#include <bits/stdc++.h>
#include <utility>
#include <vector>
using namespace std;
pair <vector<int>, long long> transaction(long long M);
void buy_souvenirs(int N, long long P0) {
	pair <vector<int>, long long> res;
	if ( N == 2 ) {
		transaction ( P0 - 1 );
	} else if ( N == 3 ) {
		res = transaction ( P0 - 1 );
		if ( res.first.size() == 1 ) {
			transaction ( P0 - 1 - res.second - 1 );
			transaction ( P0 - 1 - res.second - 1 );
		} else {
			transaction ( ( P0 - 1 - res.second ) / 2 );
		}
	} else if ( P0 == N ) {
		for ( int i = 1; i < N; i++ ) {
			for ( int j = 0; j < i; j++ ) {
				transaction ( N - i );
			}
		}
	} else {
		pair <long long, long long> a[N];
		fill ( a, a + n, { 0, 0 } );
		a[0] = { P0, 1 };
		for ( int i = 1; i < N; i++ ) {
			res = transaction( a[i - 1].first - 2 );
			if ( i == N - 1 ) {
				while ( a[i].second < i ) {
					a[i].second++;
					transaction( a[i - 1].first - 1 );
				}
			} else if ( res.first[0] == i ) {
				a[i].first = a[i - 1].first - 2;
				a[i].second++;
				while ( a[i].second < i ) {
					a[i].second++;
					transaction( a[i - 1].second - 2 );
				}
			} else {
				a[i].first = a[i - 1].first;
				a[i + 1].second++;
				while ( a[i].second < i ) {
					a[i].second++;
					transaction( a[i - 1].second - 1 );
				}
			}
		}
	}
	return;
}
