제출 #1212014

#제출 시각아이디문제언어결과실행 시간메모리
1212014al95ireyizTopical (NOI23_topical)C++20
40 / 100
1094 ms23728 KiB
//*** Bismillah ***//
#pragma GCC optimize("O3", "fast-math", "unroll-loops", "no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define len(x) (ll)(x).size()
#define all(x) x.begin(),x.end()

ll n, k;
void _(ll tt) {
    cin >> n >> k;
    vector<vll> req(n, vll(k)), gain(n, vll(k));
    for(ll i = 0; i < n; i++)
        for(ll j = 0; j < k; j++) cin >> req[i][j];
    for(ll i = 0; i < n; i++)
        for(ll j = 0; j < k; j++) cin >> gain[i][j];

    vll know(k, 0);
    vector<bool> done(n, 0);
    queue<ll> q;

    for(ll i = 0; i < n; i++) {
        bool ok = 1;
        for(ll j = 0; j < k; j++) {
            if(know[j] < req[i][j]) {
                ok = 0;
                break;
            }
        }
        if(ok) q.push(i), done[i] = 1;
    }

    ll ans = 0;
    while(!q.empty()) {
        ll i = q.front(); q.pop();
        ans++;
        for(ll j = 0; j < k; j++) know[j] += gain[i][j];

        for(ll x = 0; x < n; x++) {
            if(done[x]) continue;
            bool ok = 1;
            for(ll j = 0; j < k; j++) {
                if(know[j] < req[x][j]) {
                    ok = 0;
                    break;
                }
            }
            if(ok) {
                q.push(x);
                done[x] = 1;
            }
        }
    }

    cout << ans << '\n';
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    ll t = 1;
    _(t);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...