Submission #480778

# Submission time Handle Problem Language Result Execution time Memory
480778 2021-10-18T03:34:13 Z hollwo_pelw timeismoney (balkan11_timeismoney) C++17
25 / 100
2000 ms 620 KB
/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/
 
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
 
using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
 
void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
	if (fopen(filein.c_str(), "r")){
		freopen(filein.c_str(), "r", stdin);
		freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
		freopen(fileerr.c_str(), "w", stderr);
#endif
	}
	cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}
 
void Hollwo_Pelw();
 
signed main(){
#ifdef hollwo_pelw_local
	FAST_IO("input.inp", "output.out", "error.err");
	auto start = chrono::steady_clock::now();
#else
	FAST_IO("balkan11_timeismoney.inp", "balkan11_timeismoney.out");
#endif
	int testcases = 1;
	// cin >> testcases;
	for (int test = 1; test <= testcases; test++){
		// cout << "Case #" << test << ": ";
		Hollwo_Pelw();
	}
#ifdef hollwo_pelw_local
	auto end = chrono::steady_clock::now();
	cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
	return 0;
}

const int N = 205;
const long double inf = 1e14;

struct edge {
	int u, v, t, c;
	long double val;
	edge (int _u = 0, int _v = 0, int _t = 0, int _c = 0, long double _val = 0)
		: u(_u), v(_v), t(_t), c(_c), val(_val) {}
	bool operator < (const edge &o) const {
		return val < o.val + 1e-9;
	}
};

vector<edge> ed;
vector<pair<int, int>> choose;

int n, m, par[N];

struct disjoint_set {
	disjoint_set(int _n = N) {
		iota(par, par + n, 0);
	}

	inline int find(int u) {
		return par[u] = par[u] == u ? u : find(par[u]);
	}

	inline bool merge(int u, int v) {
		if ((u = find(u)) == (v = find(v)))
			return 0;
		return par[u] = v, 1;
	}
};

inline long long calc(const long double& st, bool print = 0) {
	for (auto &[u, v, t, c, val] : ed)
		val = t * st + c * (inf - st);

	sort(ed.begin(), ed.end());

	disjoint_set dsu(n);
	int tott = 0, totc = 0;

	for (auto [u, v, t, c, val] : ed) {
		if (dsu.merge(u, v)) {
			tott += t, totc += c;
			if (print)
				choose.emplace_back(u, v);
		}
	}

	if (print) {
		cout << tott << ' ' << totc << '\n';
		for (auto [u, v] : choose)
			cout << u << ' ' << v << '\n';
	}
	return tott * totc;
}

void Hollwo_Pelw() {
	cin >> n >> m;

	ed.resize(m);
	for (auto &[u, v, t, c, val] : ed)
		cin >> u >> v >> t >> c;
	
	long double l = 0, r = inf;
	while (r - l > 1e-5) {
		long double lm = (l + l + r) / 3, rm = (l + r + r) / 3;
		(calc(lm) < calc(rm) ? r = rm : l = lm);
	}
	calc(l, 1);
}

Compilation message

timeismoney.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
timeismoney.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
timeismoney.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 2079 ms 204 KB Time limit exceeded
2 Execution timed out 2073 ms 332 KB Time limit exceeded
3 Execution timed out 2036 ms 204 KB Time limit exceeded
4 Execution timed out 2032 ms 204 KB Time limit exceeded
5 Execution timed out 2095 ms 204 KB Time limit exceeded
6 Execution timed out 2094 ms 204 KB Time limit exceeded
7 Execution timed out 2091 ms 332 KB Time limit exceeded
8 Execution timed out 2083 ms 588 KB Time limit exceeded
9 Execution timed out 2057 ms 204 KB Time limit exceeded
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Execution timed out 2089 ms 204 KB Time limit exceeded
13 Execution timed out 2089 ms 204 KB Time limit exceeded
14 Incorrect 5 ms 332 KB Output isn't correct
15 Execution timed out 2049 ms 204 KB Time limit exceeded
16 Correct 28 ms 376 KB Output is correct
17 Execution timed out 2071 ms 332 KB Time limit exceeded
18 Correct 32 ms 332 KB Output is correct
19 Execution timed out 2096 ms 588 KB Time limit exceeded
20 Correct 152 ms 620 KB Output is correct