답안 #704569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
704569 2023-03-02T09:53:17 Z tonowak Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 2412 KB
#include "bits/stdc++.h" // Tomasz Nowak
using namespace std;     // University of Warsaw
using LL = long long;
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define REP(i, n) FOR(i, 0, (n) - 1)
#define ssize(x) int(x.size())
template<class A, class B> auto& operator<<(ostream &o, pair<A, B> p) {
	return o << '(' << p.first << ", " << p.second << ')';
}
template<class T> auto operator<<(ostream &o, T x) -> decltype(x.end(), o) {
	o << '{'; int i = 0; for(auto e : x) o << (", ")+2*!i++ << e; return o << '}';
}
#ifdef DEBUG
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#else
#define debug(...) {}
#endif

LL get_ans(map<int, LL> ants, map<int, LL> sugars, int l) {
	LL ret = 0;
	while(not ants.empty() and not sugars.empty()) {
		auto [x, cnt] = *ants.begin();
		if(cnt == 0)
			ants.erase(ants.begin());
		else {
			auto [x_s, cnt_s] = *sugars.begin();
			if(cnt_s == 0 or x_s < x - l)
				sugars.erase(sugars.begin());
			else if(x < x_s - l)
				ants.erase(ants.begin());
			else {
				LL taking = min(cnt, cnt_s);
				ants.begin()->second -= taking;
				sugars.begin()->second -= taking;
				ret += taking;
			}
		}
	}
	return ret;
}

int main() {
	cin.tie(0)->sync_with_stdio(0);

	int q, l;
	cin >> q >> l;
	map<int, LL> ants, sugars;

	while(q --> 0) {
		int ti, xi, ai;
		cin >> ti >> xi >> ai;
		(ti == 1 ? ants : sugars)[xi] += ai;
		cout << get_ans(ants, sugars, l) << endl;
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 127 ms 576 KB Output is correct
7 Correct 89 ms 456 KB Output is correct
8 Correct 29 ms 384 KB Output is correct
9 Correct 25 ms 432 KB Output is correct
10 Correct 335 ms 844 KB Output is correct
11 Correct 290 ms 752 KB Output is correct
12 Correct 296 ms 764 KB Output is correct
13 Correct 304 ms 712 KB Output is correct
14 Correct 182 ms 732 KB Output is correct
15 Correct 285 ms 692 KB Output is correct
16 Correct 246 ms 708 KB Output is correct
17 Correct 181 ms 716 KB Output is correct
18 Correct 195 ms 712 KB Output is correct
19 Correct 284 ms 844 KB Output is correct
20 Correct 179 ms 668 KB Output is correct
21 Correct 294 ms 760 KB Output is correct
22 Correct 181 ms 852 KB Output is correct
23 Correct 298 ms 656 KB Output is correct
24 Correct 185 ms 716 KB Output is correct
25 Correct 300 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Execution timed out 4066 ms 2192 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Execution timed out 4057 ms 2412 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 127 ms 576 KB Output is correct
7 Correct 89 ms 456 KB Output is correct
8 Correct 29 ms 384 KB Output is correct
9 Correct 25 ms 432 KB Output is correct
10 Correct 335 ms 844 KB Output is correct
11 Correct 290 ms 752 KB Output is correct
12 Correct 296 ms 764 KB Output is correct
13 Correct 304 ms 712 KB Output is correct
14 Correct 182 ms 732 KB Output is correct
15 Correct 285 ms 692 KB Output is correct
16 Correct 246 ms 708 KB Output is correct
17 Correct 181 ms 716 KB Output is correct
18 Correct 195 ms 712 KB Output is correct
19 Correct 284 ms 844 KB Output is correct
20 Correct 179 ms 668 KB Output is correct
21 Correct 294 ms 760 KB Output is correct
22 Correct 181 ms 852 KB Output is correct
23 Correct 298 ms 656 KB Output is correct
24 Correct 185 ms 716 KB Output is correct
25 Correct 300 ms 764 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 0 ms 212 KB Output is correct
29 Execution timed out 4066 ms 2192 KB Time limit exceeded
30 Halted 0 ms 0 KB -