Submission #668787

# Submission time Handle Problem Language Result Execution time Memory
668787 2022-12-05T01:18:25 Z vuavisao Lasers (NOI19_lasers) C++14
65 / 100
117 ms 28456 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;

template<typename Lhs, typename Rhs> inline void Max_self(Lhs &a, Rhs b) { a = (a > b ? a : b); }
template<typename Lhs, typename Rhs> inline void Min_self(Lhs &a, Rhs b) { a = (a < b ? a : b); }

const int N = 5e5 + 10;

int LEN, n;
vector<vector<int>> door;

namespace sub1_2 {
    bool check() {
        for(int i = 0; i < n; ++ i) if(door[i].size() != 1) return false;
        return true;
    }

    void solve() {
        int best = 0;
        for(int i = 0; i < n; ++ i) {
            Max_self(best, door[i][0]);
        }
        int res = 2 * max(0, best - (LEN / 2));
        if(res > 0) res -= (LEN & 1);
        cout << res;
    }
}

namespace sub3_4 {
    bool check() {
        bool check_sub = false;
        if(LEN <= 1000000 && n == 2) check_sub = true;
        int cnt_door = 0;
        for(int i = 0; i < n; ++ i) cnt_door += door[i].size();
        if(LEN <= 1000 && cnt_door <= 1000) check_sub = true;
        return check_sub;
    }
    vector<vector<int>> pred;

    int sum_to(int l, int r, int idx) {
        if(l > r) return 0;
        if(l == 0) return pred[idx][r];
        return pred[idx][r] - pred[idx][l - 1];
    }

    bool calc_line(int idx) {
        for(int i = 0; i < n; ++ i) {
            const auto& psy = pred[i];
            int first = lower_bound(psy.begin(), psy.end(), idx) - psy.begin();
            int len_last = sum_to(first, psy.size() - 1, i);
            if(LEN - len_last + 1 <= idx) return false;
        }
        return true;
    }

    void solve() {
        for(int i = 0; i < n; ++ i) {
            auto psy = door[i];
            vector<int> tmp(psy.size());
            for(int j = 0; j < psy.size(); ++ j) {
                if(j == 0) tmp[j] = psy[j];
                else tmp[j] = tmp[j - 1] + psy[j];
            }
            pred.push_back(tmp);
        }
        int res = 0;
        for(int i = 1; i <= LEN; ++ i) res += calc_line(i);
        cout << LEN - res;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("lasers.inp", "r")) {
        freopen("lasers.inp", "r", stdin);
        freopen("lasers.out", "w", stdout);
    }
    cin >> LEN >> n;
    for(int i = 1; i <= n; ++ i) {
        int cnt; cin >> cnt;
        vector<int> tmp(cnt);
        for(int j = 0; j < cnt; ++ j) cin >> tmp[j];
        door.push_back(tmp);
    }
    if(sub1_2::check()) {
        sub1_2::solve();
        return 0;
    }
    if(sub3_4::check()) {
        sub3_4::solve();
        return 0;
    }
    return 0;
}

/// Code by vuavisao

Compilation message

lasers.cpp: In function 'void sub3_4::solve()':
lasers.cpp:63:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |             for(int j = 0; j < psy.size(); ++ j) {
      |                            ~~^~~~~~~~~~~~
lasers.cpp: In function 'int32_t main()':
lasers.cpp:80:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         freopen("lasers.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
lasers.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen("lasers.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 115 ms 27344 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 117 ms 27812 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 4184 KB Output is correct
2 Correct 40 ms 1504 KB Output is correct
3 Correct 58 ms 1664 KB Output is correct
4 Correct 78 ms 5040 KB Output is correct
5 Correct 31 ms 2920 KB Output is correct
6 Correct 92 ms 6900 KB Output is correct
7 Correct 16 ms 340 KB Output is correct
8 Correct 94 ms 7468 KB Output is correct
9 Correct 44 ms 2620 KB Output is correct
10 Correct 68 ms 5600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 72 ms 4184 KB Output is correct
2 Correct 40 ms 1504 KB Output is correct
3 Correct 58 ms 1664 KB Output is correct
4 Correct 78 ms 5040 KB Output is correct
5 Correct 31 ms 2920 KB Output is correct
6 Correct 92 ms 6900 KB Output is correct
7 Correct 16 ms 340 KB Output is correct
8 Correct 94 ms 7468 KB Output is correct
9 Correct 44 ms 2620 KB Output is correct
10 Correct 68 ms 5600 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 108 ms 28456 KB Output is correct
22 Incorrect 9 ms 1492 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 260 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 115 ms 27344 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 117 ms 27812 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 72 ms 4184 KB Output is correct
22 Correct 40 ms 1504 KB Output is correct
23 Correct 58 ms 1664 KB Output is correct
24 Correct 78 ms 5040 KB Output is correct
25 Correct 31 ms 2920 KB Output is correct
26 Correct 92 ms 6900 KB Output is correct
27 Correct 16 ms 340 KB Output is correct
28 Correct 94 ms 7468 KB Output is correct
29 Correct 44 ms 2620 KB Output is correct
30 Correct 68 ms 5600 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 324 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 212 KB Output is correct
41 Correct 108 ms 28456 KB Output is correct
42 Incorrect 9 ms 1492 KB Output isn't correct
43 Halted 0 ms 0 KB -