제출 #1270963

#제출 시각아이디문제언어결과실행 시간메모리
1270963soabTopical (NOI23_topical)C++20
0 / 100
1 ms328 KiB
// soab

#include <bits/stdc++.h>

using namespace std;

#define int long long 
#define nl '\n'

void io() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}   

const int maxn = 1e6 + 1;
int n, k, p[maxn] = {0};
int cnt = 0, st;
bool valid;

int sub1() {
    return valid? 1 : 0;
}

int sub2(vector<vector<int>>& r, vector<vector<int>>& u) {
    vector<bool> vis(maxn, 0);
    queue<int> q;
    for(int i = 1; i <= n; i++) {
        bool temp = 1;
        for(int j = 1; j <= k; j++) {
            if(r[i][j] != 0) {
                temp = 0;
                break;
            }
        }
        if(temp) q.push(i);
    }
    
    while(!q.empty()) {
        int v = q.front();
        vis[v] = 1;
        q.pop();

        for(int j = 1; j <= k; j++) {
            p[j] += u[v][j];
        } 

        for(int i = 1; i <= n; i++) {
            bool add = 1;
            for(int j = 1; j <= k; j++) {
                if(r[i][j] > p[j]) {
                    add = 0;
                    break;
                }
            }
            if(add && !vis[i]) q.push(i);
        }
    }
    
    int ans = 0;
    for(int i = 1; i <= n; i++) ans += vis[i];

    return ans;
}


signed main() {
    io();

    cin >> n >> k;
    vector<vector<int>> r(n + 1, vector<int>(k + 1));
    vector<vector<int>> u(n + 1, vector<int>(k + 1));
    // int r[n + 1][k + 1], u[n + 1][k + 1];

    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k; j++) {
            cin >> r[i][j];
            cnt += r[i][j];
        }
    }

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

    valid = cnt != 0;

    if(!valid) return cout << 0, 0;
    // for(int i = 1; i <= n; i++) {
    //     for(int j = 1; j <= k; j++) {
    //         cout << u[i][j] << ' ';
    //     }
    //     cout << nl;
    // }
    if(n == 1) {
        sub1();
    } else {
        if(!valid) return cout << 0, 0;
        cout << sub2(r, u);
    }


    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...