Submission details
Task:Drink Responsibly
Sender:wavelets
Submission time:2015-11-25 19:35:54 +0200
Language:C++
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.05 sdetails
#20.14 sdetails
#30.15 sdetails
#40.15 sdetails
#50.14 sdetails
#60.13 sdetails

Code

#include <iostream>
#include <vector>
#include <cstdint>
#include <sstream>
using namespace std;
int64_t gcd(int64_t a,int64_t b){return b==0?a:gcd(b,a%b);}
struct fraction:pair<int64_t,int64_t>{
	fraction(int64_t a=0,int64_t b=1):pair<int64_t,int64_t>(a,b){int64_t c=gcd(a,b);first/=c;second/=c;}
	fraction operator-(const fraction&v){return fraction(first*v.second-second*v.first,second*v.second);}
	fraction operator*(int64_t a){return fraction(first*a,second);}
};
struct node{
	int pi;
	string name;
	int n;
	int m;
	fraction v;
};
int main(){
	double mv,uv,d;
	cin>>mv>>uv>>d;
	int m=mv*100;
	int u=uv*10;
	vector<node> v;
	v.push_back({-1,"",-1,m,fraction(u,1)});
	for(int i=0;i<d;++i){
		string name;
		int p;
		string fr;
		cin>>name>>p>>fr>>uv;
		int c=uv*100;
		if(p==0&&c==0)continue;
		fraction f(p*10,fr[2]-'0');
		vector<node> ins;
		int cnt=v.size();
		for(int j=0;j<cnt;++j){
			auto& it = v[j];
			if(it.m<c)continue;
			int n=0;
			while(++n){
				fraction vvv = it.v-f*n;
				if(vvv.first<0)break;
				if(it.m-c*n<0)break;
				v.push_back({j,name,n,it.m-c*n,vvv});
			}
		}
	}
	for(auto&it:v){
		if(it.m!=0)continue;
		if(it.v.first!=0)continue;
		cout<<it.name<<' '<<it.n<<'\n';
		int i=it.pi;
		while(i>0){
			 cout<<v[i].name<<' '<<v[i].n<<'\n';
			 i=v[i].pi;
		}
		goto end;
	}
	cout<<"IMPOSSIBLE\n";
end:return 0;
}


Test details

Test 1

Verdict: ACCEPTED

input
3.93 19.0 8
punkipa 4 1/1 0.27
deadpony 5 1/2 0.59
vagabond 3 1/1 0.27
thisislager 3 1/2 0.51
...

correct output
bomber 1
kronenbourg 3
vagabond 2
vodka 2

user output
kronenbourg 3
bomber 1
deadpony 4

Test 2

Verdict:

input
3.59 17.0 8
punkipa 6 1/3 0.41
deadpony 6 1/1 0.63
vagabond 6 1/3 0.97
thisislager 1 1/3 0.08
...

correct output
punkipa 4
vagabond 1
vodka 2

user output
(empty)

Test 3

Verdict:

input
3.14 19.5 8
punkipa 6 1/3 0.01
deadpony 3 1/2 0.34
vagabond 6 1/3 0.85
thisislager 3 1/3 0.66
...

correct output
bomber 1
fiveamred 4
kronenbourg 1
vagabond 1
vodka 1

user output
(empty)

Test 4

Verdict:

input
9.61 20.0 8
punkipa 1 1/2 0.63
deadpony 2 1/3 0.49
vagabond 2 1/3 0.80
thisislager 3 1/1 0.12
...

correct output
bomber 2
fiveamred 5
kronenbourg 2
vagabond 2
vodka 4

user output
(empty)

Test 5

Verdict:

input
6.24 16.1 8
punkipa 6 1/3 0.48
deadpony 3 1/3 0.09
vagabond 7 1/1 0.04
thisislager 1 1/2 0.76
...

correct output
IMPOSSIBLE

user output
(empty)

Test 6

Verdict:

input
5.84 20.0 8
punkipa 5 1/2 0.73
deadpony 4 1/1 0.94
vagabond 5 1/3 0.01
thisislager 5 1/2 0.62
...

correct output
deadpony 2
fiveamred 4
vodka 8

user output
(empty)