답안 #615056

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
615056 2022-07-31T06:26:03 Z 박상훈(#8491) Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1236 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

void solve(vector<pair<int, int>> A[], int d){
    sort(A[0].begin(), A[0].end());
    sort(A[1].begin(), A[1].end());
    A[0].emplace_back(2e9, 0);
    A[1].emplace_back(2e9, 0);

    deque<pair<int, int>> dq;
    int typ = 0, pt[2] = {0, 0};

    ll ans = 0;

    while(pt[0]<(int)A[0].size()-1 || pt[1]<(int)A[1].size()-1){
        int cur = 0;
        if (A[0][pt[0]].first > A[1][pt[1]].first) cur = 1;

        if (typ==cur){
            dq.push_back(A[cur][pt[cur]]);
            pt[cur]++;
        }
        else{
            auto p = A[cur][pt[cur]];
            while(!dq.empty()){
                if (p.first - dq.front().first > d) {dq.pop_front(); continue;}

                ans += min(p.second, dq.front().second);

                //printf("%d %d -> %d\n", p.first, dq.front().first, min(p.second, dq.front().second));

                if (p.second >= dq.front().second){
                    p.second -= dq.front().second;
                    dq.pop_front();


                }
                else{
                    dq.front().second -= p.second;
                    p.second = 0;
                }

                if (p.second == 0) {/*printf("ok %d %d\n", p.first, p.second);*/break; }
            }

            //printf(" %d %d\n", p.first, p.second);

            if (p.second > 0){
                //printf("YES %d %d\n", p.first, p.second);
                assert(dq.empty());
                typ = cur;
                dq.push_back(p);

            }

            pt[cur]++;

        }
    }

    A[0].pop_back();
    A[1].pop_back();

    printf("%lld\n", ans);
}

int main(){
    int n, d;
    scanf("%d %d", &n, &d);
    vector<pair<int, int>> A[2];
    for (int i=1;i<=n;i++){
        int t, x, y;
        scanf("%d %d %d", &t, &x, &y);
        A[t-1].emplace_back(x, y);
        solve(A, d);
    }
    return 0;
}

Compilation message

sugar.cpp: In function 'int main()':
sugar.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     scanf("%d %d", &n, &d);
      |     ~~~~~^~~~~~~~~~~~~~~~~
sugar.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         scanf("%d %d %d", &t, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 72 ms 296 KB Output is correct
7 Correct 51 ms 340 KB Output is correct
8 Correct 20 ms 340 KB Output is correct
9 Correct 13 ms 336 KB Output is correct
10 Correct 159 ms 376 KB Output is correct
11 Correct 150 ms 396 KB Output is correct
12 Correct 158 ms 464 KB Output is correct
13 Correct 172 ms 460 KB Output is correct
14 Correct 184 ms 408 KB Output is correct
15 Correct 184 ms 492 KB Output is correct
16 Correct 185 ms 520 KB Output is correct
17 Correct 176 ms 408 KB Output is correct
18 Correct 191 ms 380 KB Output is correct
19 Correct 152 ms 340 KB Output is correct
20 Correct 181 ms 528 KB Output is correct
21 Correct 179 ms 388 KB Output is correct
22 Correct 235 ms 460 KB Output is correct
23 Correct 156 ms 648 KB Output is correct
24 Correct 185 ms 400 KB Output is correct
25 Correct 153 ms 416 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 4054 ms 1236 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Execution timed out 4051 ms 1044 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 296 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 72 ms 296 KB Output is correct
7 Correct 51 ms 340 KB Output is correct
8 Correct 20 ms 340 KB Output is correct
9 Correct 13 ms 336 KB Output is correct
10 Correct 159 ms 376 KB Output is correct
11 Correct 150 ms 396 KB Output is correct
12 Correct 158 ms 464 KB Output is correct
13 Correct 172 ms 460 KB Output is correct
14 Correct 184 ms 408 KB Output is correct
15 Correct 184 ms 492 KB Output is correct
16 Correct 185 ms 520 KB Output is correct
17 Correct 176 ms 408 KB Output is correct
18 Correct 191 ms 380 KB Output is correct
19 Correct 152 ms 340 KB Output is correct
20 Correct 181 ms 528 KB Output is correct
21 Correct 179 ms 388 KB Output is correct
22 Correct 235 ms 460 KB Output is correct
23 Correct 156 ms 648 KB Output is correct
24 Correct 185 ms 400 KB Output is correct
25 Correct 153 ms 416 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 4054 ms 1236 KB Time limit exceeded
30 Halted 0 ms 0 KB -