답안 #877806

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
877806 2023-11-23T14:59:25 Z vjudge1 Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1344 KB
// https://oj.uz/problem/view/JOI22_sugar

#include <bits/stdc++.h>
using namespace std;

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);

        int q, L;
        cin >> q >> L;
        vector<pair<int, int>> ant, sugar;
        while (q--) {
                int t, a, x;
                cin >> t >> x >> a;
                auto& which = t == 1 ? ant : sugar;
                which.emplace_back(x, a);
                sort(which.begin(), which.end());
                int j = 0;
                int64_t remain = sugar.size() ? sugar[0].second : -1;
                int64_t res = 0;
                for (int i = 0; i < ant.size(); i++) {
                        int64_t total_ants = ant[i].second;
                        while (j < sugar.size() && sugar[j].first < ant[i].first - L) j++, remain = j < sugar.size() ? sugar[j].second : -1;
                        while (j < sugar.size() && (sugar[j].first - ant[i].first) <= L && total_ants > 0) {
                                int64_t take = min(total_ants, remain);
                                res += take;
                                if (remain <= take) {
                                        total_ants -= remain;
                                        j++;
                                        remain = remain = j < sugar.size() ? sugar[j].second : -1;
                                } else {
                                        total_ants = 0;
                                        remain -= take;
                                }
                        }
                }
                cout << res << '\n';
        }
}

Compilation message

sugar.cpp: In function 'int32_t main()':
sugar.cpp:22:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |                 for (int i = 0; i < ant.size(); i++) {
      |                                 ~~^~~~~~~~~~~~
sugar.cpp:24:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |                         while (j < sugar.size() && sugar[j].first < ant[i].first - L) j++, remain = j < sugar.size() ? sugar[j].second : -1;
      |                                ~~^~~~~~~~~~~~~~
sugar.cpp:24:103: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |                         while (j < sugar.size() && sugar[j].first < ant[i].first - L) j++, remain = j < sugar.size() ? sugar[j].second : -1;
      |                                                                                                     ~~^~~~~~~~~~~~~~
sugar.cpp:25:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |                         while (j < sugar.size() && (sugar[j].first - ant[i].first) <= L && total_ants > 0) {
      |                                ~~^~~~~~~~~~~~~~
sugar.cpp:31:61: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |                                         remain = remain = j < sugar.size() ? sugar[j].second : -1;
      |                                                           ~~^~~~~~~~~~~~~~
sugar.cpp:31:48: warning: operation on 'remain' may be undefined [-Wsequence-point]
   31 |                                         remain = remain = j < sugar.size() ? sugar[j].second : -1;
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 34 ms 516 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 6 ms 348 KB Output is correct
10 Correct 68 ms 548 KB Output is correct
11 Correct 71 ms 588 KB Output is correct
12 Correct 73 ms 592 KB Output is correct
13 Correct 72 ms 812 KB Output is correct
14 Correct 139 ms 592 KB Output is correct
15 Correct 137 ms 572 KB Output is correct
16 Correct 138 ms 552 KB Output is correct
17 Correct 145 ms 344 KB Output is correct
18 Correct 142 ms 344 KB Output is correct
19 Correct 68 ms 584 KB Output is correct
20 Correct 146 ms 544 KB Output is correct
21 Correct 74 ms 596 KB Output is correct
22 Correct 144 ms 600 KB Output is correct
23 Correct 77 ms 348 KB Output is correct
24 Correct 141 ms 528 KB Output is correct
25 Correct 77 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 456 KB Output is correct
4 Execution timed out 4074 ms 1344 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Execution timed out 4029 ms 1288 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 34 ms 516 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 6 ms 348 KB Output is correct
10 Correct 68 ms 548 KB Output is correct
11 Correct 71 ms 588 KB Output is correct
12 Correct 73 ms 592 KB Output is correct
13 Correct 72 ms 812 KB Output is correct
14 Correct 139 ms 592 KB Output is correct
15 Correct 137 ms 572 KB Output is correct
16 Correct 138 ms 552 KB Output is correct
17 Correct 145 ms 344 KB Output is correct
18 Correct 142 ms 344 KB Output is correct
19 Correct 68 ms 584 KB Output is correct
20 Correct 146 ms 544 KB Output is correct
21 Correct 74 ms 596 KB Output is correct
22 Correct 144 ms 600 KB Output is correct
23 Correct 77 ms 348 KB Output is correct
24 Correct 141 ms 528 KB Output is correct
25 Correct 77 ms 592 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 456 KB Output is correct
29 Execution timed out 4074 ms 1344 KB Time limit exceeded
30 Halted 0 ms 0 KB -