Task: | Drink Responsibly |
Sender: | OOliOO_slayer |
Submission time: | 2015-11-25 18:46:43 +0200 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.06 s | details |
#2 | ACCEPTED | 0.06 s | details |
#3 | ACCEPTED | 0.06 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | ACCEPTED | 0.05 s | details |
Code
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <map> #include <sstream> #include <utility> #include <set> #include <iomanip> using namespace std; typedef long long LL; LL inf = 1e15; int main(){ cin.tie(0); ios_base::sync_with_stdio(0); double budget_in, target_in; LL nDrinks; cin >> budget_in >> target_in >> nDrinks; LL budget = budget_in * 100; LL target = target_in * 30; vector<string> names; vector<LL> values, costs; for(int i = 0; i < nDrinks; i++){ string s; cin >> s; // name names.push_back(s); LL value; cin >> value; string fraction; cin >> fraction; double cost; cin >> cost; LL x = fraction[2] - '0'; value = (value * 30) / x; values.push_back(value); costs.push_back(cost*100); } /*cout << target << " " << budget << endl; for(auto x : values) cout << x << " "; cout << endl; for(auto x : costs) cout << x << " "; cout << endl;*/ vector<vector<LL> > T(target + 5, vector<LL>(nDrinks + 5, inf)); vector<vector<LL> > backpointers(target + 5, vector<LL>(nDrinks + 5)); T[0][0] = 0; for(int k = 1; k <= nDrinks; k++){ for(int value = 0; value <= target; value++){ LL dontuse = T[value][k-1]; LL usesame = value - values[k-1] >= 0 ? T[value-values[k-1]][k] + costs[k-1] : inf; LL usedifferent = value - values[k-1] >= 0 ? T[value-values[k-1]][k-1] + costs[k-1] : inf; LL best = min(dontuse,min(usesame,usedifferent)); if(dontuse == best) backpointers[value][k] = 1; if(usedifferent == best) backpointers[value][k] = 2; if(usesame == best) backpointers[value][k] = 3; //if(best != inf) cout << value << " " << k << ": " << best << endl; T[value][k] = best; } } if(T[target][nDrinks] > budget){ cout << "IMPOSSIBLE" << endl; } else{ vector<LL> counts(nDrinks+1); int value = target; int k = nDrinks; while(k != 0){ if(backpointers[value][k] == 1) k--; else if(backpointers[value][k] == 2) { value -= values[k-1]; counts[k-1]++; k--; } else{ counts[k-1]++; value -= values[k-1]; } } for(int i = 0; i < nDrinks; i++){ if(counts[i] != 0){ cout << names[i] << " " << counts[i] << "\n"; } } } }
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 |
---|
punkipa 3 bomber 1 |
Test 2
Verdict: ACCEPTED
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 |
---|
punkipa 2 deadpony 2 thisislager 3 |
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 |
---|
deadpony 1 fiveamred 9 |
Test 4
Verdict: ACCEPTED
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 |
---|
thisislager 6 bomber 2 |
Test 5
Verdict: ACCEPTED
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 |
---|
IMPOSSIBLE |
Test 6
Verdict: ACCEPTED
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 |
---|
vagabond 12 |