제출 #1063290

#제출 시각아이디문제언어결과실행 시간메모리
1063290CodeLakVNLasers (NOI19_lasers)C++17
65 / 100
90 ms33384 KiB
#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 */

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...