답안 #880220

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880220 2023-11-29T03:39:49 Z Regulus Ants and Sugar (JOI22_sugar) C++17
6 / 100
4000 ms 3668 KB
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(false);cin.tie(0);
#define debug(x) cerr << #x << " = " << (x) << ' '
#define endl cerr << '\n'
#define all(v) (v).begin(), (v).end()
#define SZ(v) (ll)(v).size()
#define lowbit(x) (x)&-(x)
#define pb emplace_back
#define F first
#define S second
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

const int N = 1e5+5;
ll t[N], a[N], x[N];
map<ll, ll> mp[3];      // ant, sugar

int main(void)
{ IO
    ll Q, i, j, ans, L, tmp;

    cin >> Q >> L;
    for (i=1; i <= Q; ++i)
    {
        cin >> t[i] >> x[i] >> a[i];
        mp[1].clear(), mp[2].clear();
        for (j=1; j <= i; ++j) mp[t[j]][x[j]] += a[j];

        ans = 0;
        auto it2 = mp[2].begin();
        for (auto it = mp[1].begin(); it != mp[1].end() && it2 != mp[2].end(); ++it)
        {
            while (it->S > 0)
            {
                while (it2 != mp[2].end() && (it->F - it2->F > L || it2->S == 0)) ++it2;
                if (it2 == mp[2].end()) break;
                if (abs(it->F-it2->F) > L) break;
                tmp = min(it->S, it2->S);
                it->S -= tmp, it2->S -= tmp, ans += tmp;
            }
        }
        cout << ans << '\n';
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 202 ms 3156 KB Output is correct
7 Correct 135 ms 2644 KB Output is correct
8 Correct 32 ms 2396 KB Output is correct
9 Correct 27 ms 2396 KB Output is correct
10 Correct 501 ms 3000 KB Output is correct
11 Correct 502 ms 2652 KB Output is correct
12 Correct 500 ms 2788 KB Output is correct
13 Correct 503 ms 2900 KB Output is correct
14 Correct 440 ms 2752 KB Output is correct
15 Correct 478 ms 2960 KB Output is correct
16 Correct 482 ms 2680 KB Output is correct
17 Correct 440 ms 2644 KB Output is correct
18 Correct 442 ms 2900 KB Output is correct
19 Correct 495 ms 2800 KB Output is correct
20 Correct 449 ms 2884 KB Output is correct
21 Correct 504 ms 3152 KB Output is correct
22 Correct 437 ms 2644 KB Output is correct
23 Correct 500 ms 3016 KB Output is correct
24 Correct 441 ms 2644 KB Output is correct
25 Correct 497 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2512 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Execution timed out 4088 ms 3588 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Execution timed out 4018 ms 3668 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 202 ms 3156 KB Output is correct
7 Correct 135 ms 2644 KB Output is correct
8 Correct 32 ms 2396 KB Output is correct
9 Correct 27 ms 2396 KB Output is correct
10 Correct 501 ms 3000 KB Output is correct
11 Correct 502 ms 2652 KB Output is correct
12 Correct 500 ms 2788 KB Output is correct
13 Correct 503 ms 2900 KB Output is correct
14 Correct 440 ms 2752 KB Output is correct
15 Correct 478 ms 2960 KB Output is correct
16 Correct 482 ms 2680 KB Output is correct
17 Correct 440 ms 2644 KB Output is correct
18 Correct 442 ms 2900 KB Output is correct
19 Correct 495 ms 2800 KB Output is correct
20 Correct 449 ms 2884 KB Output is correct
21 Correct 504 ms 3152 KB Output is correct
22 Correct 437 ms 2644 KB Output is correct
23 Correct 500 ms 3016 KB Output is correct
24 Correct 441 ms 2644 KB Output is correct
25 Correct 497 ms 2644 KB Output is correct
26 Correct 1 ms 2512 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Execution timed out 4088 ms 3588 KB Time limit exceeded
30 Halted 0 ms 0 KB -