답안 #488130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488130 2021-11-17T22:50:58 Z TruaShamu Cloud Computing (CEOI18_clo) C++17
100 / 100
776 ms 2000 KB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

using vi = vector<int>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()

using pi = pair<int, int>;
#define f first
#define s second
#define mp make_pair

void setIO(string name = "") {
	cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
	if (sz(name)) {
		freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
		freopen((name + ".out").c_str(), "w", stdout);
	}
}



struct event {
	int cores;
	int rate;
	int price;
	bool operator < (const event& b) const {
		return rate != b.rate ? rate > b.rate : price < b.price;
	}
};

int main() {
	setIO();
	vector<event> events;
	int N; cin >> N;
	// Computer
	int maxComp = 0;
	for (int i = 0; i < N; i++) {
		event oEvent;
		cin >> oEvent.cores >> oEvent.rate >> oEvent.price;
		oEvent.price *= -1;
		events.pb(oEvent);
		maxComp += oEvent.cores;
	}

	// Order
	int M; cin >> M;
	for (int i = 0; i < M; i++) {
		event oEvent;
		cin >> oEvent.cores >> oEvent.rate >> oEvent.price;
		oEvent.cores *= -1;
		events.pb(oEvent);
	}

	// Print
	std::sort(events.begin(), events.end());
	vector<ll> dp(maxComp + 1, INT64_MIN);
	dp[0] = 0;
	for (const event& oEvent : events) {
		vector<ll> newMax(dp);
		for (int c = 0; c <= maxComp; c++) {
			int prevComp = c - oEvent.cores;
			if (prevComp >= 0 && prevComp <= maxComp && dp[prevComp] != INT64_MIN) {
				newMax[c] = max(newMax[c], dp[prevComp] + oEvent.price);
			}
		}
		dp = newMax;
	}
	cout << *max_element(dp.begin(), dp.end());
}

Compilation message

clo.cpp: In function 'void setIO(std::string)':
clo.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((name + ".in").c_str(), "r", stdin); // see /general/input-output
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:20:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 4 ms 408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 37 ms 716 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 209 ms 1100 KB Output is correct
8 Correct 29 ms 460 KB Output is correct
9 Correct 273 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 11 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 334 ms 1212 KB Output is correct
6 Correct 620 ms 1872 KB Output is correct
7 Correct 624 ms 1872 KB Output is correct
8 Correct 569 ms 1808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 39 ms 716 KB Output is correct
4 Correct 9 ms 368 KB Output is correct
5 Correct 717 ms 1812 KB Output is correct
6 Correct 624 ms 1804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 4 ms 332 KB Output is correct
8 Correct 4 ms 408 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 37 ms 716 KB Output is correct
14 Correct 2 ms 332 KB Output is correct
15 Correct 209 ms 1100 KB Output is correct
16 Correct 29 ms 460 KB Output is correct
17 Correct 273 ms 1740 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 11 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 334 ms 1212 KB Output is correct
31 Correct 620 ms 1872 KB Output is correct
32 Correct 624 ms 1872 KB Output is correct
33 Correct 569 ms 1808 KB Output is correct
34 Correct 0 ms 204 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 39 ms 716 KB Output is correct
37 Correct 9 ms 368 KB Output is correct
38 Correct 717 ms 1812 KB Output is correct
39 Correct 624 ms 1804 KB Output is correct
40 Correct 53 ms 720 KB Output is correct
41 Correct 123 ms 848 KB Output is correct
42 Correct 8 ms 336 KB Output is correct
43 Correct 632 ms 2000 KB Output is correct
44 Correct 608 ms 2000 KB Output is correct
45 Correct 776 ms 1992 KB Output is correct
46 Correct 4 ms 336 KB Output is correct
47 Correct 9 ms 448 KB Output is correct
48 Correct 9 ms 452 KB Output is correct