제출 #1329167

#제출 시각아이디문제언어결과실행 시간메모리
1329167thanhsonTopical (NOI23_topical)C++20
40 / 100
1096 ms28364 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
using namespace std;

mt19937_64 rng(time(NULL));

ll rand(ll l, ll r) {
  return rng() % (r - l + 1) + l;
}

ll power(ll a, ll b) {
  if (b == 0) return 1;
  ll ans = power(a, b / 2);
  ans *= ans;
  if (b % 2 == 1) ans *= a;
  return ans;
}

const ll N = 1e6 + 5;
ll n, k, p[N], cnt[N];
vector<vector<ll>> r, u;

void solve() {
    cin >> n >> k;
    for (int i = 0; i < k; i ++) p[i] = 0;
    for (int i = 0; i < n; i ++) {
        r.push_back({});
        for (int j = 0; j < k; j ++) {
            ll x; cin >> x;
            r[i].push_back(x);
        }
    }
    for (int i = 0; i < n; i ++) {
        u.push_back({});
        for (int j = 0; j < k; j ++) {
            ll x; cin >> x;
            u[i].push_back(x);
        }
    }
    if (n == 1) {
        bool ok = true;
        for (int i = 0; i < k; i ++) {
           if (r[0][i] != 0) {
               ok = false;
               break;
           }
       }
       if (ok == true) {cout << 1; return;}
       cout << 0; return;
    }
    else {
        ll t = 0;
        bool nig = true;
        while (nig == true) {
            nig = false;
            for (int i = 0; i < n; i ++) if (cnt[i] == 0) {
                bool ok = true;
                for (int j = 0; j < k; j ++) {
                    if (p[j] < r[i][j]) {
                        ok = false;
                        break;
                    }
                }
                if (ok == true) {
                    for (int j = 0; j < k; j ++) {
                        p[j] += u[i][j];
                    }
                    t ++;
                    cnt[i] ++;
                    nig = true;
                }
            }
        }
        cout << t;
    }
}

int main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ll query = 1;
  // cin >> query;
  while (query --) solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...