제출 #303708

#제출 시각아이디문제언어결과실행 시간메모리
303708JooDdaePacking Biscuits (IOI20_biscuits)C++17
21 / 100
1093 ms122816 KiB
#include<bits/stdc++.h>
#include "biscuits.h"
using namespace std;
using ll = long long;

ll INF = 1e18;

ll count_tastiness(ll x, vector<ll> a) {
	if(x == 1){
		ll ans = 1;

		priority_queue<pair<ll, ll>> pq;
		for(int i=a.size()-1;i>=0;i--){
			ll u = 1ll << i;
			if(a[i]){
				ll p = 0;
				
				queue<pair<ll, ll>> q;
				while(!pq.empty() && pq.top().first > u){
					auto [x, y] = pq.top(); pq.pop();

					ll s = min(x / u - 1, a[i]);
					p += s * y;
					ans += s * y;
					if(x > u * s) q.push({x - u * s, y});
					else p += y;
				}

				while(!q.empty()) pq.push(q.front()), q.pop();
				ans += a[i];
				pq.push({u, a[i] + p});
			}
		}
		
		return ans;
	}
	
	ll ans = 0, sum = 0;
	for(int i=0;i<a.size();i++) sum += (1ll << i) * a[i];

	ll mx = sum / x;
	while((1ll << a.size()) < mx) a.push_back(0);

	queue<ll> qu, qc, ql;
	qu.push(0), qc.push(0), ql.push(0), ans++;
	set<pair<ll, ll>> s;

	while(!qu.empty()){
		ll u = qu.front(), c = qc.front(), l = ql.front() / 2 + a[c]; qu.pop(), qc.pop(), ql.pop();
		if(u + (1ll << c) > mx || s.count({u, c})) continue;
		s.insert({u, c});

		qu.push(u), qc.push(c + 1), ql.push(l);
		if(l >= x) qu.push(u + (1ll << c)), qc.push(c + 1), ql.push(l - x), ans++;
	}

	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

biscuits.cpp: In function 'll count_tastiness(ll, std::vector<long long int>)':
biscuits.cpp:39:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i=0;i<a.size();i++) sum += (1ll << i) * a[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...