CSES - BAPC 2017 - Results
Submission details
Task:Lemonade Trade
Sender:Antti Röyskö
Submission time:2017-10-24 19:41:02 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.25 sdetails
#2ACCEPTED0.41 sdetails
#3ACCEPTED0.34 sdetails
#4ACCEPTED0.28 sdetails
#5ACCEPTED0.30 sdetails
#6ACCEPTED0.41 sdetails
#7ACCEPTED0.41 sdetails
#8ACCEPTED0.29 sdetails
#9ACCEPTED0.29 sdetails
#10ACCEPTED0.03 sdetails
#11ACCEPTED0.04 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:30:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < offers.size(); ++i) {
                                  ^
input/code.cpp:69:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < revised.size(); ++i) {
                                   ^

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <math.h>
#include <iomanip>

const long double inf = 1e9;

int main() {
	int n;
	std::cin >> n;
	std::vector<std::pair<std::pair<std::string, std::string>, long double>> offers;
	std::vector<std::pair<std::pair<int, int>, long double>> revised;
	std::vector<std::string> strings;
	strings.push_back("blue");
	strings.push_back("pink");
	for (int i = 0; i < n; ++i) {
		std::string a, b;
		long double ratio;
		std::cin >> a >> b >> ratio;
		strings.push_back(a);
		strings.push_back(b);
		offers.push_back({{a, b}, ratio});
	}
	std::sort(strings.begin(), strings.end());
	strings.erase(std::unique(strings.begin(), strings.end()), strings.end());
	int m = strings.size();
	for (int i = 0; i < offers.size(); ++i) {
		int low = 0;
		int high = m - 1;
		while(low != high) {
			int mid = (low + high) / 2;
			if (strings[mid] < offers[i].first.first) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		int first = low;
		low = 0;
		high = m - 1;
		while(low != high) {
			int mid = (low + high) / 2;
			if (strings[mid] < offers[i].first.second) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		int second = low;
		revised.push_back({{first, second}, offers[i].second});
	}
	int pink = -1;
	int blue = -1;
	for (int i = 0; i < m; ++i) {
		if (strings[i] == "pink") {
			pink = i;
		} else if (strings[i] == "blue") {
			blue = i;
		}
	}
	std::vector<long double> amounts (m);
	for (int i = 0; i < m; ++i) {
		amounts[i] = -inf;
	}
	amounts[pink] = 0;
	for (int i = 0; i < revised.size(); ++i) {
		int o = revised[i].first.first;
		int w = revised[i].first.second;
		// std::cout << o << ' ' << w << ' ' << amounts[o] << ' ' << amounts[w] << ' ' << log(revised[i].second) << '\n';
		amounts[o] = std::max(amounts[o], amounts[w] + log(revised[i].second));
	}
	/*
	std::cout << pink << ' ' << blue << '\n';
	for (int i = 0; i < m; ++i) {
		std::cout << amounts[i] << ' ';
	}
	std::cout << '\n';
	*/
	if (amounts[blue] > log(10)) {
		std::cout << 10 << '\n';
	} else {
		std::cout << std::fixed << std::setprecision(20) << exp(amounts[blue]) << '\n';
	}
}










Test details

Test 1

Verdict: ACCEPTED

input
100000
blue pink 0.999999
pink blue 0.999999
blue pink 1.000001
pink blue 1.000001
...

correct output
1.0512700

user output
1.05127001881992154786

Test 2

Verdict: ACCEPTED

input
100000
c1 pink 1.99999
c2 c1 1.99999
c3 c2 1.99999
c4 c3 1.99999
...

correct output
0.999998749994228

user output
0.99999874999421889399

Test 3

Verdict: ACCEPTED

input
100000
c1 pink 0.5000025
c2 c1 0.5000025
c3 c2 0.5000025
c4 c3 0.5000025
...

correct output
0.999998749994231

user output
0.99999874999421956012

Test 4

Verdict: ACCEPTED

input
99858
0 pink 1.000000
0 0 1.000001
1 0 1.000001
2 0 1.000001
...

correct output
1.0006312

user output
1.00063119880662898531

Test 5

Verdict: ACCEPTED

input
99542
0 pink 1.000000
1 0 1.000001
2 0 1.000001
3 0 1.000001
...

correct output
1.0003150

user output
1.00031504946013427571

Test 6

Verdict: ACCEPTED

input
100000
c1 pink 1.999999
c2 c1 1.999999
c3 c2 1.999999
c4 c3 1.999999
...

correct output
10.000000000000000

user output
10

Test 7

Verdict: ACCEPTED

input
100000
1 pink 1.25
2 pink 1.25
3 1 0.8
3 2 0.7
...

correct output
1.000000

user output
1.00000000000138777878

Test 8

Verdict: ACCEPTED

input
99542
blue 315 1.000000
1 0 1.000001
2 0 1.000001
3 0 1.000001
...

correct output
0.000000

user output
0.00000000000000000000

Test 9

Verdict: ACCEPTED

input
99540
1 0 1.000001
2 0 1.000001
3 0 1.000001
4 0 1.000001
...

correct output
0.000000

user output
0.00000000000000000000

Test 10

Verdict: ACCEPTED

input
5
orange pink 1.9
yellow orange 1.9
green yellow 1.9
black green 1.9
...

correct output
6.646371000000000

user output
6.64637099999999758637

Test 11

Verdict: ACCEPTED

input
0

correct output
0.000000

user output
0.00000000000000000000