답안 #1087199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1087199 2024-09-12T09:24:07 Z avighna Lasers (NOI19_lasers) C++17
100 / 100
656 ms 72368 KB
#include <bits/stdc++.h>

typedef long long ll;

int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  ll l, r;
  std::cin >> l >> r;
  std::priority_queue<std::pair<ll, ll>, std::vector<std::pair<ll, ll>>,
                      std::greater<>>
      pq;
  std::vector<ll> left(r), sum(r);
  std::vector<std::vector<ll>> rows(r);
  std::multiset<ll> st;
  // x blocks from right ==> l - x + 1 from left
  auto f = [&](ll cnt) { return l - (sum[cnt] - left[cnt]) + 1; };
  for (ll cnt = 0; cnt < r; ++cnt) {
    auto &v = rows[cnt];
    ll len;
    std::cin >> len;
    v.resize(len);
    for (auto &i : v) {
      std::cin >> i;
    }
    std::reverse(v.begin(), v.end());
    sum[cnt] = std::accumulate(v.begin(), v.end(), 0LL);
    pq.push({left[cnt] + v.back(), cnt});
    v.pop_back();
    st.insert(f(cnt));
  }

  auto get = [](ll l, ll r, ll c) {
    if (r <= c) {
      return r - l + 1;
    }
    if (l > c) {
      return 0LL;
    }
    return c - l + 1;
  };

  ll ans = l;
  for (ll _i = 1; _i <= l; ++_i) {
    while (!pq.empty() and pq.top().first < _i) {
      auto [l, i] = pq.top();
      pq.pop();
      st.erase(st.find(f(i)));
      left[i] = l;
      st.insert(f(i));
      if (!rows[i].empty()) {
        pq.push({left[i] + rows[i].back(), i});
        rows[i].pop_back();
      }
    }
    ll beg = _i, end = !pq.empty() ? pq.top().first : l;
    ans -= get(beg + 1, end + 1, *st.begin());
    _i = end;
  }
  std::cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 179 ms 71440 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 629 ms 72368 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3492 KB Output is correct
2 Correct 6 ms 1116 KB Output is correct
3 Correct 9 ms 1372 KB Output is correct
4 Correct 24 ms 3336 KB Output is correct
5 Correct 11 ms 1884 KB Output is correct
6 Correct 30 ms 4372 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 39 ms 4824 KB Output is correct
9 Correct 14 ms 2096 KB Output is correct
10 Correct 35 ms 3828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 3492 KB Output is correct
2 Correct 6 ms 1116 KB Output is correct
3 Correct 9 ms 1372 KB Output is correct
4 Correct 24 ms 3336 KB Output is correct
5 Correct 11 ms 1884 KB Output is correct
6 Correct 30 ms 4372 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 39 ms 4824 KB Output is correct
9 Correct 14 ms 2096 KB Output is correct
10 Correct 35 ms 3828 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 448 KB Output is correct
21 Correct 618 ms 70812 KB Output is correct
22 Correct 39 ms 2140 KB Output is correct
23 Correct 13 ms 1372 KB Output is correct
24 Correct 75 ms 4984 KB Output is correct
25 Correct 611 ms 70728 KB Output is correct
26 Correct 81 ms 3672 KB Output is correct
27 Correct 32 ms 1880 KB Output is correct
28 Correct 639 ms 70364 KB Output is correct
29 Correct 609 ms 70828 KB Output is correct
30 Correct 46 ms 3928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 452 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 179 ms 71440 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 629 ms 72368 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 25 ms 3492 KB Output is correct
22 Correct 6 ms 1116 KB Output is correct
23 Correct 9 ms 1372 KB Output is correct
24 Correct 24 ms 3336 KB Output is correct
25 Correct 11 ms 1884 KB Output is correct
26 Correct 30 ms 4372 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 39 ms 4824 KB Output is correct
29 Correct 14 ms 2096 KB Output is correct
30 Correct 35 ms 3828 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 0 ms 448 KB Output is correct
41 Correct 618 ms 70812 KB Output is correct
42 Correct 39 ms 2140 KB Output is correct
43 Correct 13 ms 1372 KB Output is correct
44 Correct 75 ms 4984 KB Output is correct
45 Correct 611 ms 70728 KB Output is correct
46 Correct 81 ms 3672 KB Output is correct
47 Correct 32 ms 1880 KB Output is correct
48 Correct 639 ms 70364 KB Output is correct
49 Correct 609 ms 70828 KB Output is correct
50 Correct 46 ms 3928 KB Output is correct
51 Correct 17 ms 1884 KB Output is correct
52 Correct 597 ms 71568 KB Output is correct
53 Correct 608 ms 71600 KB Output is correct
54 Correct 63 ms 3420 KB Output is correct
55 Correct 148 ms 7248 KB Output is correct
56 Correct 44 ms 4556 KB Output is correct
57 Correct 98 ms 4700 KB Output is correct
58 Correct 656 ms 72000 KB Output is correct
59 Correct 70 ms 3596 KB Output is correct
60 Correct 104 ms 5216 KB Output is correct