답안 #336423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336423 2020-12-15T10:08:42 Z ncduy0303 Lasers (NOI19_lasers) C++17
100 / 100
149 ms 10076 KB
#include <bits/stdc++.h>

using namespace std;

#define ar array
#define ll long long

const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;



void solve() {
    int len, n; cin >> len >> n;
    vector<ar<int,2>> block; // all ranges where the laser cannot pass through
    for (int i = 0; i < n; i++) {
        int m; cin >> m;
        vector<int> ps(m + 1);
        for (int i = 1; i <= m; i++) {
            cin >> ps[i];
            ps[i] += ps[i - 1];
        }
        for (int i = 1; i <= m; i++) {
            int l = len - (ps[m] - ps[i - 1]) + 1;
            int r = ps[i];
            if (l <= r) block.push_back({l, r});
        }
    }
    sort(block.begin(), block.end());
    if (block.empty()) {
        cout << 0 << "\n";
        return;
    }
    int ans = 0;
    auto rng = block[0];
    for (int i = 1; i < block.size(); i++) {
        auto new_rng = block[i];
        if (rng[1] + 1 < new_rng[0]) {
            ans += rng[1] - rng[0] + 1;
            rng = new_rng;
        }
        else {
            rng[1] = max(rng[1], new_rng[1]);
        }
    }
    ans += rng[1] - rng[0] + 1;
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int tc = 1;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}

Compilation message

lasers.cpp: In function 'void solve()':
lasers.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 1; i < block.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 136 ms 10076 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 125 ms 7908 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 3576 KB Output is correct
2 Correct 8 ms 1132 KB Output is correct
3 Correct 9 ms 928 KB Output is correct
4 Correct 54 ms 3824 KB Output is correct
5 Correct 20 ms 2404 KB Output is correct
6 Correct 41 ms 2540 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 37 ms 2888 KB Output is correct
9 Correct 23 ms 3044 KB Output is correct
10 Correct 48 ms 4004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 3576 KB Output is correct
2 Correct 8 ms 1132 KB Output is correct
3 Correct 9 ms 928 KB Output is correct
4 Correct 54 ms 3824 KB Output is correct
5 Correct 20 ms 2404 KB Output is correct
6 Correct 41 ms 2540 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 37 ms 2888 KB Output is correct
9 Correct 23 ms 3044 KB Output is correct
10 Correct 48 ms 4004 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 134 ms 6756 KB Output is correct
22 Correct 21 ms 1588 KB Output is correct
23 Correct 12 ms 1376 KB Output is correct
24 Correct 50 ms 3728 KB Output is correct
25 Correct 127 ms 6736 KB Output is correct
26 Correct 40 ms 3700 KB Output is correct
27 Correct 20 ms 1544 KB Output is correct
28 Correct 141 ms 6756 KB Output is correct
29 Correct 142 ms 6972 KB Output is correct
30 Correct 38 ms 2484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 136 ms 10076 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 125 ms 7908 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 41 ms 3576 KB Output is correct
22 Correct 8 ms 1132 KB Output is correct
23 Correct 9 ms 928 KB Output is correct
24 Correct 54 ms 3824 KB Output is correct
25 Correct 20 ms 2404 KB Output is correct
26 Correct 41 ms 2540 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
28 Correct 37 ms 2888 KB Output is correct
29 Correct 23 ms 3044 KB Output is correct
30 Correct 48 ms 4004 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 364 KB Output is correct
37 Correct 1 ms 364 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 134 ms 6756 KB Output is correct
42 Correct 21 ms 1588 KB Output is correct
43 Correct 12 ms 1376 KB Output is correct
44 Correct 50 ms 3728 KB Output is correct
45 Correct 127 ms 6736 KB Output is correct
46 Correct 40 ms 3700 KB Output is correct
47 Correct 20 ms 1544 KB Output is correct
48 Correct 141 ms 6756 KB Output is correct
49 Correct 142 ms 6972 KB Output is correct
50 Correct 38 ms 2484 KB Output is correct
51 Correct 17 ms 1676 KB Output is correct
52 Correct 132 ms 8036 KB Output is correct
53 Correct 149 ms 7908 KB Output is correct
54 Correct 30 ms 2944 KB Output is correct
55 Correct 84 ms 5228 KB Output is correct
56 Correct 51 ms 4000 KB Output is correct
57 Correct 47 ms 4596 KB Output is correct
58 Correct 131 ms 8036 KB Output is correct
59 Correct 35 ms 2680 KB Output is correct
60 Correct 47 ms 3832 KB Output is correct