Task: | Drink Responsibly |
Sender: | wavelets |
Submission time: | 2015-11-25 19:39:14 +0200 |
Language: | C++ |
Status: | READY |
Result: | RUNTIME ERROR |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | RUNTIME ERROR | 0.15 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | RUNTIME ERROR | 0.14 s | details |
#5 | RUNTIME ERROR | 0.14 s | details |
#6 | RUNTIME ERROR | 0.14 s | details |
Code
#include <iostream> #include <vector> #include <cstdint> #include <sstream> #include <set> 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; set<pair<int,fraction>> val; 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; int cc=it.m-c*n; if(vvv.first<0)break; if(cc<0)break; if(val.count({cc,vvv}))continue; val.insert({cc,vvv}); v.push_back({j,name,n,cc,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: RUNTIME ERROR
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: ACCEPTED
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 |
---|
vodka 1 kronenbourg 1 bomber 1 vagabond 1 punkipa 4 |
Test 4
Verdict: RUNTIME ERROR
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: RUNTIME ERROR
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: RUNTIME ERROR
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) |