답안 #906703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906703 2024-01-14T19:28:06 Z vjudge1 Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 1916 KB
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)

#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)

#define NN
#define M 1000000007 // 998244353
ll L;
ll solve(vector<pl> ants, vector<pl> sugars) {
    ll ans = 0;
    ll ap = 0, sp = 0;
    while (ap < ants.size() and sp < sugars.size()) {
        if (!ants[ap].V) {
            ++ap; continue;
        }
        if (!sugars[sp].V) {
            ++sp; continue;
        }
        
        ll left = ants[ap].K - L, right = ants[ap].K + L;
        if (left <= sugars[sp].K and sugars[sp].K <= right) {
            ll sub = min(ants[ap].V, sugars[sp].V);
            ants[ap].V -= sub;
            sugars[sp].V -= sub;
            ans += sub;
            continue;;
        } else if (right < sugars[sp].K) ap++;
        else sp++;
    }
    return ans;
}

int main(){
//    freopen("a.in", "r", stdin);
//    freopen("a.out", "w", stdout);

    ios_base::sync_with_stdio(false); cin.tie(0);
    cout << fixed << setprecision(20);
    G(q) cin >> L;
    vector<pl> ants, sugars;
    while (q--) {
        G(t) G(x) G(a)
        (t == 1 ? ants: sugars).emplace_back(x, a);
        sort(A(ants)); sort(A(sugars));

        cout << solve(ants, sugars) << endl;
    }
}

Compilation message

sugar.cpp: In function 'll solve(std::vector<std::pair<long long int, long long int> >, std::vector<std::pair<long long int, long long int> >)':
sugar.cpp:30:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (ap < ants.size() and sp < sugars.size()) {
      |            ~~~^~~~~~~~~~~~~
sugar.cpp:30:36: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     while (ap < ants.size() and sp < sugars.size()) {
      |                                 ~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 46 ms 608 KB Output is correct
7 Correct 33 ms 596 KB Output is correct
8 Correct 10 ms 348 KB Output is correct
9 Correct 9 ms 348 KB Output is correct
10 Correct 87 ms 664 KB Output is correct
11 Correct 92 ms 636 KB Output is correct
12 Correct 103 ms 704 KB Output is correct
13 Correct 98 ms 604 KB Output is correct
14 Correct 136 ms 604 KB Output is correct
15 Correct 141 ms 612 KB Output is correct
16 Correct 136 ms 676 KB Output is correct
17 Correct 136 ms 604 KB Output is correct
18 Correct 134 ms 604 KB Output is correct
19 Correct 93 ms 916 KB Output is correct
20 Correct 138 ms 604 KB Output is correct
21 Correct 95 ms 676 KB Output is correct
22 Correct 137 ms 648 KB Output is correct
23 Correct 98 ms 604 KB Output is correct
24 Correct 140 ms 604 KB Output is correct
25 Correct 102 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 476 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 4034 ms 1916 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 708 KB Output is correct
2 Execution timed out 4062 ms 1464 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 46 ms 608 KB Output is correct
7 Correct 33 ms 596 KB Output is correct
8 Correct 10 ms 348 KB Output is correct
9 Correct 9 ms 348 KB Output is correct
10 Correct 87 ms 664 KB Output is correct
11 Correct 92 ms 636 KB Output is correct
12 Correct 103 ms 704 KB Output is correct
13 Correct 98 ms 604 KB Output is correct
14 Correct 136 ms 604 KB Output is correct
15 Correct 141 ms 612 KB Output is correct
16 Correct 136 ms 676 KB Output is correct
17 Correct 136 ms 604 KB Output is correct
18 Correct 134 ms 604 KB Output is correct
19 Correct 93 ms 916 KB Output is correct
20 Correct 138 ms 604 KB Output is correct
21 Correct 95 ms 676 KB Output is correct
22 Correct 137 ms 648 KB Output is correct
23 Correct 98 ms 604 KB Output is correct
24 Correct 140 ms 604 KB Output is correct
25 Correct 102 ms 604 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 476 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Execution timed out 4034 ms 1916 KB Time limit exceeded
30 Halted 0 ms 0 KB -