답안 #571988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
571988 2022-06-03T08:43:29 Z 8e7 Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1536 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ...b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 100005
#define pii pair<ll, ll>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
int main() {
	io
	int q, l;
	cin >> q >> l;
	vector<pii> v1, v2, t2;
	while (q--) {
		{
			int t, x;
			ll v;
			cin >> t >> x >> v;
			if (t == 1) {
				v1.push_back({x, v});
			} else {
				t2.push_back({x, v});
			}
		}
		v2 = t2;
		sort(v1.begin(), v1.end());
		sort(v2.begin(), v2.end());
		int ind = 0;
		ll ans = 0;
		for (int i = 0;i < v1.size();i++) {
			ll tmp = v1[i].ss;
			while (ind < v2.size()) {
				if (v2[ind].ff < v1[i].ff - l) ind++;
				else if (v2[ind].ff > v1[i].ff + l) {
					break;
				} else if (v2[ind].ss < tmp) {
					ans += v2[ind].ss;
					tmp -= v2[ind].ss;
					ind++;
				} else {
					ans += tmp;
					v2[ind].ss -= tmp;
					break;
				}
			}
		}
		cout << ans << "\n";
	}
}

Compilation message

sugar.cpp: In function 'int main()':
sugar.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int i = 0;i < v1.size();i++) {
      |                  ~~^~~~~~~~~~~
sugar.cpp:44:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |    while (ind < v2.size()) {
      |           ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 85 ms 420 KB Output is correct
7 Correct 63 ms 456 KB Output is correct
8 Correct 15 ms 340 KB Output is correct
9 Correct 15 ms 340 KB Output is correct
10 Correct 167 ms 468 KB Output is correct
11 Correct 190 ms 456 KB Output is correct
12 Correct 178 ms 588 KB Output is correct
13 Correct 163 ms 592 KB Output is correct
14 Correct 229 ms 576 KB Output is correct
15 Correct 244 ms 620 KB Output is correct
16 Correct 174 ms 488 KB Output is correct
17 Correct 140 ms 472 KB Output is correct
18 Correct 169 ms 516 KB Output is correct
19 Correct 180 ms 624 KB Output is correct
20 Correct 151 ms 480 KB Output is correct
21 Correct 168 ms 520 KB Output is correct
22 Correct 147 ms 560 KB Output is correct
23 Correct 167 ms 612 KB Output is correct
24 Correct 146 ms 428 KB Output is correct
25 Correct 194 ms 520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Execution timed out 4070 ms 1536 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 4070 ms 1188 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 85 ms 420 KB Output is correct
7 Correct 63 ms 456 KB Output is correct
8 Correct 15 ms 340 KB Output is correct
9 Correct 15 ms 340 KB Output is correct
10 Correct 167 ms 468 KB Output is correct
11 Correct 190 ms 456 KB Output is correct
12 Correct 178 ms 588 KB Output is correct
13 Correct 163 ms 592 KB Output is correct
14 Correct 229 ms 576 KB Output is correct
15 Correct 244 ms 620 KB Output is correct
16 Correct 174 ms 488 KB Output is correct
17 Correct 140 ms 472 KB Output is correct
18 Correct 169 ms 516 KB Output is correct
19 Correct 180 ms 624 KB Output is correct
20 Correct 151 ms 480 KB Output is correct
21 Correct 168 ms 520 KB Output is correct
22 Correct 147 ms 560 KB Output is correct
23 Correct 167 ms 612 KB Output is correct
24 Correct 146 ms 428 KB Output is correct
25 Correct 194 ms 520 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 324 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Execution timed out 4070 ms 1536 KB Time limit exceeded
30 Halted 0 ms 0 KB -