Submission #1327823

#TimeUsernameProblemLanguageResultExecution timeMemory
1327823illuminastormTopical (NOI23_topical)C++20
12 / 100
1094 ms78680 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;

    vector<vector<long long>> r(n, vector<long long>(k));
    vector<vector<long long>> u(n, vector<long long>(k));

    for(int i = 0; i < n; i++)
        for(int j = 0; j < k; j++)
            cin >> r[i][j];

    for(int i = 0; i < n; i++)
        for(int j = 0; j < k; j++)
            cin >> u[i][j];

    vector<long long> p(k, 0);
    vector<int> need(n, 0);
    vector<vector<int>> waiting(k);
    for(int i = 0; i < n; i++){
        int cnt = 0;
        for(int j = 0; j < k; j++){
            if(r[i][j] > 0){
                cnt++;
                waiting[j].push_back(i);
            }
        }
        need[i] = cnt;
    }

    queue<int> q;
    for(int i = 0; i < n; i++){
        bool ok = true;
        for(int j = 0; j < k; j++){
            if(p[j] < r[i][j]){
                ok = false;
                break;
            }
        }
        if(ok) q.push(i);
    }

    int ans = 0;
    vector<bool> done(n, false);

    while(!q.empty()){
        int i = q.front(); q.pop();
        if(done[i]) continue;

        done[i] = true;
        ans++;

        for(int j = 0; j < k; j++){
            long long before = p[j];
            p[j] += u[i][j];

            if(p[j] > before){
                for(int module : waiting[j]){
                    if(!done[module]){
                        if(p[j] >= r[module][j]){
                            need[module]--;
                            if(need[module] == 0){
                                q.push(module);
                            }
                        }
                    }
                }
            }
        }
    }

    cout << ans;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...