Submission #1169575

#TimeUsernameProblemLanguageResultExecution timeMemory
1169575ThanhsTopical (NOI23_topical)C++20
100 / 100
321 ms86260 KiB
#include <bits/stdc++.h>
using namespace std;

#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))

mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}

vector<vector<pair<int, int>>> v;
vector<vector<int>> u;
vector<int> c, cnt, wait;
int n, k, ans;

void upd(int x)
{
    ans++;
    for (int i = 1; i <= k; i++)
    {
        c[i] += u[x][i];
        while (v[i].size() && v[i].back().fi <= c[i])
        {
            cnt[v[i].back().se]++;
            if (cnt[v[i].back().se] == k)
                wait.push_back(v[i].back().se);
            v[i].pop_back();
        }
    }
}

void solve()
{
    cin >> n >> k;
    v.resize(k + 1);
    c.resize(k + 1);
    cnt.resize(n + 1);
    u.resize(n + 1, vector<int>(k + 1));
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= k; j++)
        {
            int x;
            cin >> x;
            v[j].push_back({x, i});
        }
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= k; j++)
            cin >> u[i][j];
    for (int i = 1; i <= k; i++)
    {
        sort(v[i].begin(), v[i].end(), greater<>());
        while (v[i].size() && v[i].back().fi == 0)
        {
            cnt[v[i].back().se]++;
            if (cnt[v[i].back().se] == k)
                wait.push_back(v[i].back().se);
            v[i].pop_back();
        }
    }
    while (wait.size())
    {
        int t = wait.back();
        wait.pop_back();
        upd(t);
    }
    cout << ans << endl;
}

signed main()
{
    if (fopen("in.txt", "r")) 
    {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    else if (fopen(name".inp", "r"))
    {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int tc = 1; 
    // cin >> tc;
    while (tc--)
        solve();
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:79:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen(name".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...