Submission #816405

# Submission time Handle Problem Language Result Execution time Memory
816405 2023-08-09T05:00:29 Z 반딧불(#10124) Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1268 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int q; ll L;
vector<pair<ll, ll> > ant, sugar;

void solve(){
    deque<pair<ll, ll> > que;
    int pnt = 0;
    ll ret = 0;
    for(int i=0; i<(int)ant.size(); i++){
        while(pnt < (int)sugar.size()&& ant[i].first + L >= sugar[pnt].first){
            que.push_back(sugar[pnt++]);
        }
        while(!que.empty() && que.front().first < ant[i].first - L) que.pop_front();
        ll v = ant[i].second;
        while(v && !que.empty()){
            ll v2 = que.front().second;
            if(v >= v2) v -= v2, ret += v2, que.pop_front();
            else{
                v2 -= v, ret += v, v = 0;
                ll x = que.front().first; que.pop_front();
                que.push_front(make_pair(x, v2));
            }
        }
    }
    printf("%lld\n", ret);
}

int main(){
    scanf("%d %lld", &q, &L);
    for(int i=1; i<=q; i++){
        int t; ll x, a;
        scanf("%d %lld %lld", &t, &x, &a);
        if(t==1) ant.push_back(make_pair(x, a));
        else sugar.push_back(make_pair(x, a));
        sort(ant.begin(), ant.end());
        sort(sugar.begin(), sugar.end());
        solve();
    }
}

Compilation message

sugar.cpp: In function 'int main()':
sugar.cpp:34:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |     scanf("%d %lld", &q, &L);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
sugar.cpp:37:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         scanf("%d %lld %lld", &t, &x, &a);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 56 ms 380 KB Output is correct
7 Correct 40 ms 340 KB Output is correct
8 Correct 10 ms 308 KB Output is correct
9 Correct 10 ms 340 KB Output is correct
10 Correct 109 ms 412 KB Output is correct
11 Correct 116 ms 520 KB Output is correct
12 Correct 121 ms 488 KB Output is correct
13 Correct 120 ms 464 KB Output is correct
14 Correct 149 ms 464 KB Output is correct
15 Correct 162 ms 516 KB Output is correct
16 Correct 159 ms 428 KB Output is correct
17 Correct 161 ms 528 KB Output is correct
18 Correct 161 ms 456 KB Output is correct
19 Correct 119 ms 488 KB Output is correct
20 Correct 166 ms 456 KB Output is correct
21 Correct 124 ms 468 KB Output is correct
22 Correct 163 ms 468 KB Output is correct
23 Correct 134 ms 556 KB Output is correct
24 Correct 165 ms 424 KB Output is correct
25 Correct 127 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 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 4074 ms 1268 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 296 KB Output is correct
2 Execution timed out 4045 ms 1172 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 56 ms 380 KB Output is correct
7 Correct 40 ms 340 KB Output is correct
8 Correct 10 ms 308 KB Output is correct
9 Correct 10 ms 340 KB Output is correct
10 Correct 109 ms 412 KB Output is correct
11 Correct 116 ms 520 KB Output is correct
12 Correct 121 ms 488 KB Output is correct
13 Correct 120 ms 464 KB Output is correct
14 Correct 149 ms 464 KB Output is correct
15 Correct 162 ms 516 KB Output is correct
16 Correct 159 ms 428 KB Output is correct
17 Correct 161 ms 528 KB Output is correct
18 Correct 161 ms 456 KB Output is correct
19 Correct 119 ms 488 KB Output is correct
20 Correct 166 ms 456 KB Output is correct
21 Correct 124 ms 468 KB Output is correct
22 Correct 163 ms 468 KB Output is correct
23 Correct 134 ms 556 KB Output is correct
24 Correct 165 ms 424 KB Output is correct
25 Correct 127 ms 428 KB Output is correct
26 Correct 1 ms 296 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 4074 ms 1268 KB Time limit exceeded
30 Halted 0 ms 0 KB -