Submission #1063290

# Submission time Handle Problem Language Result Execution time Memory
1063290 2024-08-17T16:25:55 Z CodeLakVN Lasers (NOI19_lasers) C++17
65 / 100
90 ms 33384 KB
#include <bits/stdc++.h>

#define no "NO"
#define yes "YES"
#define F first
#define S second
#define vec vector
#define task "LASERS"
#define ll long long
#define _mp make_pair
#define ii pair<int, int>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define evoid(val) return void(std::cout << val)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FOD(i, b, a) for(int i = (b); i >= (a); --i)
#define unq(x) sort(all(x)); x.resize(unique(all(x)) - x.begin())

using namespace std;

template<typename U, typename V> bool maximize(U &a, V b) {
    if (a < b) { a = b; return 1; } return 0;
}
template<typename U, typename V> bool minimize(U &a, V b) {
    if (a > b) { a = b; return 1; } return 0;
}

const int N = (int)2e5 + 9;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int len, numRow;
vector<vector<int>> rows;

namespace sub1 {
    bool valid() {
        return numRow == 1 && rows[1][0] == 1;
    }

    void solve() {
        if (rows[1][1] <= len / 2) cout << 0 << "\n";
        else cout << rows[1][1] - (len - rows[1][1] + 1) + 1 << "\n";
    }
}

namespace sub2 {
    bool valid() {
        FOR(i, 1, numRow) if (rows[i][0] != 1) return false;
        return true;
    }

    void solve() {
        int maxWidth = 0;
        FOR(i, 1, numRow) maximize(maxWidth, rows[i][1]);
        if (maxWidth <= len / 2) cout << 0 << "\n";
        else cout << maxWidth - (len - maxWidth+ 1) + 1 << "\n";
    }
}

namespace sub34 {
    bool valid() {
        int sumX = 0;
        FOR(i, 1, numRow) sumX += rows[i][0];
        return ((numRow == 2 && len <= (int)1e6) || (len <= (int)1e3 && sumX <= (int)1e3));
    }

    void solve() {
        vector<vector<int>> sum;
        FOR(i, 1, numRow) {
            vector<int> curSum(rows[i][0] + 1, 0);
            FOR(j, 1, rows[i][0]) curSum[j] = curSum[j - 1] + rows[i][j];
            sum.push_back(curSum);
        }

        int ans = len;
        FOR(i, 1, len) {
            bool ok = 1;
            FOR(id, 0, numRow - 1) {
                int pos = lower_bound(sum[id].begin(), sum[id].end(), i) - sum[id].begin();
                if (pos > rows[id + 1][0]) continue;
                pos--;
                if (sum[id][rows[id + 1][0]] - sum[id][pos] >= len - i + 1) {
                    ok = 0;
                    break;
                }
            }
            if (ok) ans--;
        }
        cout << ans << "\n";
    }
}

void main_code() {
    cin >> len >> numRow;
    rows.resize(numRow + 1);
    FOR(i, 1, numRow) {
        int n;
        cin >> n;
        rows[i].push_back(n);
        FOR(j, 1, n) {
            int x;
            cin >> x;
            rows[i].push_back(x);
        }
    }

    if (sub1::valid()) sub1::solve();
    else if (sub2::valid()) sub2::solve();
    else if (sub34::valid()) sub34::solve();
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    const bool MULTITEST = 0;
    int num_test = 1; if (MULTITEST) cin >> num_test;
    while (num_test--) { main_code(); cout << "\n"; }
}

/* Lak lu theo dieu nhac */

Compilation message

lasers.cpp: In function 'int main()':
lasers.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lasers.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 76 ms 32980 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 77 ms 33384 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3820 KB Output is correct
2 Correct 23 ms 1500 KB Output is correct
3 Correct 30 ms 1436 KB Output is correct
4 Correct 52 ms 4468 KB Output is correct
5 Correct 21 ms 2292 KB Output is correct
6 Correct 57 ms 5588 KB Output is correct
7 Correct 11 ms 360 KB Output is correct
8 Correct 64 ms 6748 KB Output is correct
9 Correct 28 ms 2460 KB Output is correct
10 Correct 46 ms 4644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 0 ms 464 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3820 KB Output is correct
2 Correct 23 ms 1500 KB Output is correct
3 Correct 30 ms 1436 KB Output is correct
4 Correct 52 ms 4468 KB Output is correct
5 Correct 21 ms 2292 KB Output is correct
6 Correct 57 ms 5588 KB Output is correct
7 Correct 11 ms 360 KB Output is correct
8 Correct 64 ms 6748 KB Output is correct
9 Correct 28 ms 2460 KB Output is correct
10 Correct 46 ms 4644 KB Output is correct
11 Correct 0 ms 344 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 0 ms 464 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 90 ms 31688 KB Output is correct
22 Incorrect 7 ms 1628 KB Output isn't correct
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 344 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 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 76 ms 32980 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 77 ms 33384 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 48 ms 3820 KB Output is correct
22 Correct 23 ms 1500 KB Output is correct
23 Correct 30 ms 1436 KB Output is correct
24 Correct 52 ms 4468 KB Output is correct
25 Correct 21 ms 2292 KB Output is correct
26 Correct 57 ms 5588 KB Output is correct
27 Correct 11 ms 360 KB Output is correct
28 Correct 64 ms 6748 KB Output is correct
29 Correct 28 ms 2460 KB Output is correct
30 Correct 46 ms 4644 KB Output is correct
31 Correct 0 ms 344 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 0 ms 464 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
41 Correct 90 ms 31688 KB Output is correct
42 Incorrect 7 ms 1628 KB Output isn't correct
43 Halted 0 ms 0 KB -