답안 #931451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931451 2024-02-21T20:30:29 Z vjudge1 Gym Badges (NOI22_gymbadges) C++17
51 / 100
1252 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 5e5+5, S = 50, inf = LLONG_MAX;

int n, x[N], l[N];
pair<int, int> s[N];
map<int, int> dp[N];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  bool eq = 1;
  for (int i = 0; i < n; i++) {
    cin >> l[i];
    if (l[i] != l[0]) eq = 0;
  }
  for (int i = 0; i < n; i++) {
    s[i] = make_pair(x[i]+l[i], i);
  }
  sort(s, s+n);

  if (eq) {
    int ans = 0;
    int lvl = 0;
    for (int i = 0; i < n; i++) {
      int idx = s[i].second;
      if (lvl <= l[idx]) {
        ans++;
        lvl += x[idx];
      }
    }
    cout << ans << "\n";
  } 
  else {
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
      int cnt = 0;

      auto it = dp[i].end();
      while (it != dp[i].begin()) {
        if (cnt++ > S) break;

        --it;
        int j = it->first;
        int k = it->second;

        auto it2 = dp[i+1].find(j);
        if (it2 == dp[i+1].end()) dp[i+1][j] = k;
        else it2->second = min(it2->second, k);

        if (l[s[i].second] >= k) {
          it2 = dp[i+1].find(j+1);
          if (it2 == dp[i+1].end()) dp[i+1][j+1] = k + x[s[i].second];
          else it2->second = min(it2->second, k + x[s[i].second]);
        } 
      }
    }

    for (int i = n; i >= 0; i--) {
      if (dp[n].find(i) != dp[n].end()) {
        cout << i << "\n";
        break;
      }
    }
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 5 ms 29528 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29352 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 6 ms 29280 KB Output is correct
8 Correct 7 ms 29368 KB Output is correct
9 Correct 5 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29316 KB Output is correct
12 Correct 5 ms 29272 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 5 ms 29308 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 5 ms 29276 KB Output is correct
17 Correct 5 ms 29292 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29276 KB Output is correct
20 Correct 5 ms 29276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 48808 KB Output is correct
2 Correct 117 ms 48532 KB Output is correct
3 Correct 123 ms 48792 KB Output is correct
4 Correct 118 ms 48720 KB Output is correct
5 Correct 123 ms 48724 KB Output is correct
6 Correct 113 ms 47700 KB Output is correct
7 Correct 112 ms 47188 KB Output is correct
8 Correct 116 ms 47768 KB Output is correct
9 Correct 115 ms 47600 KB Output is correct
10 Correct 114 ms 47696 KB Output is correct
11 Correct 117 ms 46680 KB Output is correct
12 Correct 120 ms 46932 KB Output is correct
13 Correct 116 ms 46828 KB Output is correct
14 Correct 121 ms 46712 KB Output is correct
15 Correct 117 ms 46676 KB Output is correct
16 Correct 123 ms 47324 KB Output is correct
17 Correct 115 ms 47220 KB Output is correct
18 Correct 117 ms 47184 KB Output is correct
19 Correct 118 ms 47188 KB Output is correct
20 Correct 123 ms 47440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 5 ms 29528 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29352 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 6 ms 29280 KB Output is correct
8 Correct 7 ms 29368 KB Output is correct
9 Correct 5 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29316 KB Output is correct
12 Correct 5 ms 29272 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 5 ms 29308 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 5 ms 29276 KB Output is correct
17 Correct 5 ms 29292 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29276 KB Output is correct
20 Correct 5 ms 29276 KB Output is correct
21 Correct 32 ms 44628 KB Output is correct
22 Correct 31 ms 44892 KB Output is correct
23 Correct 31 ms 44508 KB Output is correct
24 Correct 30 ms 44724 KB Output is correct
25 Correct 31 ms 44624 KB Output is correct
26 Correct 31 ms 44892 KB Output is correct
27 Correct 31 ms 45140 KB Output is correct
28 Correct 32 ms 44880 KB Output is correct
29 Correct 31 ms 44892 KB Output is correct
30 Correct 31 ms 45052 KB Output is correct
31 Correct 32 ms 45328 KB Output is correct
32 Correct 31 ms 45048 KB Output is correct
33 Correct 31 ms 45056 KB Output is correct
34 Correct 34 ms 45140 KB Output is correct
35 Correct 34 ms 45396 KB Output is correct
36 Correct 32 ms 45404 KB Output is correct
37 Correct 32 ms 45148 KB Output is correct
38 Correct 31 ms 45136 KB Output is correct
39 Correct 32 ms 45140 KB Output is correct
40 Correct 32 ms 45148 KB Output is correct
41 Correct 32 ms 45404 KB Output is correct
42 Correct 31 ms 45136 KB Output is correct
43 Correct 36 ms 45396 KB Output is correct
44 Correct 32 ms 45428 KB Output is correct
45 Correct 32 ms 45148 KB Output is correct
46 Correct 32 ms 45396 KB Output is correct
47 Correct 32 ms 45420 KB Output is correct
48 Correct 31 ms 45404 KB Output is correct
49 Correct 31 ms 45140 KB Output is correct
50 Correct 32 ms 45212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29272 KB Output is correct
2 Correct 5 ms 29528 KB Output is correct
3 Correct 6 ms 29276 KB Output is correct
4 Correct 6 ms 29276 KB Output is correct
5 Correct 6 ms 29352 KB Output is correct
6 Correct 6 ms 29276 KB Output is correct
7 Correct 6 ms 29280 KB Output is correct
8 Correct 7 ms 29368 KB Output is correct
9 Correct 5 ms 29276 KB Output is correct
10 Correct 6 ms 29276 KB Output is correct
11 Correct 6 ms 29316 KB Output is correct
12 Correct 5 ms 29272 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 5 ms 29308 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 5 ms 29276 KB Output is correct
17 Correct 5 ms 29292 KB Output is correct
18 Correct 6 ms 29276 KB Output is correct
19 Correct 6 ms 29276 KB Output is correct
20 Correct 5 ms 29276 KB Output is correct
21 Correct 120 ms 48808 KB Output is correct
22 Correct 117 ms 48532 KB Output is correct
23 Correct 123 ms 48792 KB Output is correct
24 Correct 118 ms 48720 KB Output is correct
25 Correct 123 ms 48724 KB Output is correct
26 Correct 113 ms 47700 KB Output is correct
27 Correct 112 ms 47188 KB Output is correct
28 Correct 116 ms 47768 KB Output is correct
29 Correct 115 ms 47600 KB Output is correct
30 Correct 114 ms 47696 KB Output is correct
31 Correct 117 ms 46680 KB Output is correct
32 Correct 120 ms 46932 KB Output is correct
33 Correct 116 ms 46828 KB Output is correct
34 Correct 121 ms 46712 KB Output is correct
35 Correct 117 ms 46676 KB Output is correct
36 Correct 123 ms 47324 KB Output is correct
37 Correct 115 ms 47220 KB Output is correct
38 Correct 117 ms 47184 KB Output is correct
39 Correct 118 ms 47188 KB Output is correct
40 Correct 123 ms 47440 KB Output is correct
41 Correct 32 ms 44628 KB Output is correct
42 Correct 31 ms 44892 KB Output is correct
43 Correct 31 ms 44508 KB Output is correct
44 Correct 30 ms 44724 KB Output is correct
45 Correct 31 ms 44624 KB Output is correct
46 Correct 31 ms 44892 KB Output is correct
47 Correct 31 ms 45140 KB Output is correct
48 Correct 32 ms 44880 KB Output is correct
49 Correct 31 ms 44892 KB Output is correct
50 Correct 31 ms 45052 KB Output is correct
51 Correct 32 ms 45328 KB Output is correct
52 Correct 31 ms 45048 KB Output is correct
53 Correct 31 ms 45056 KB Output is correct
54 Correct 34 ms 45140 KB Output is correct
55 Correct 34 ms 45396 KB Output is correct
56 Correct 32 ms 45404 KB Output is correct
57 Correct 32 ms 45148 KB Output is correct
58 Correct 31 ms 45136 KB Output is correct
59 Correct 32 ms 45140 KB Output is correct
60 Correct 32 ms 45148 KB Output is correct
61 Correct 32 ms 45404 KB Output is correct
62 Correct 31 ms 45136 KB Output is correct
63 Correct 36 ms 45396 KB Output is correct
64 Correct 32 ms 45428 KB Output is correct
65 Correct 32 ms 45148 KB Output is correct
66 Correct 32 ms 45396 KB Output is correct
67 Correct 32 ms 45420 KB Output is correct
68 Correct 31 ms 45404 KB Output is correct
69 Correct 31 ms 45140 KB Output is correct
70 Correct 32 ms 45212 KB Output is correct
71 Correct 6 ms 29532 KB Output is correct
72 Correct 6 ms 29316 KB Output is correct
73 Runtime error 1252 ms 1048576 KB Execution killed with signal 9
74 Halted 0 ms 0 KB -