Submission #997284

#TimeUsernameProblemLanguageResultExecution timeMemory
997284cpptowinTopical (NOI23_topical)C++17
100 / 100
562 ms212636 KiB
#include <bits/stdc++.h>
#define fo(i, d, c) for (int i = d; i <= c; i++)
#define fod(i, c, d) for (int i = c; i >= d; i--)
#define maxn 1000010
#define N 1010
#define fi first
#define se second
#define pb emplace_back
#define en cout << "\n";
#define int long long
#define inf (int)1e18
#define pii pair<int, int>
#define vii vector<pii>
#define lb(x) x & -x
#define bit(i, j) ((i >> j) & 1)
#define offbit(i, j) (i ^ (1LL << j))
#define onbit(i, j) (i | (1LL << j))
#define vi vector<int>
#define all(x) x.begin(), x.end()
template <typename T1, typename T2>
bool minimize(T1 &a, T2 b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T1, typename T2>
bool maximize(T1 &a, T2 b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
using namespace std;
const int nsqrt = 450;
const int mod = 1e9 + 7;
vector<vi> r, u;
struct cmp
{
    bool operator()(array<int, 3> a, array<int, 3> b)
    {
        return a[0] > b[0] or (a[0] == b[0] and a > b);
    }
};
int n, k, cnt[maxn], p[maxn];
main()
{
#define name "TASK"
    if (fopen(name ".inp", "r"))
    {
        freopen(name ".inp", "r", stdin);
        freopen(name ".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    r.resize(n + 5);
    u.resize(n + 5);
    priority_queue<pii, vii, greater<pii>> q[k + 1];
    fo(i, 1, n)
    {
        cnt[i] = k;
        r[i].resize(k + 5);
        u[i].resize(k + 5);
    }
    fo(i, 1, n) fo(j, 1, k)
    {
        cin >> r[i][j];
        q[j].push({r[i][j], i});
    }
    fo(i, 1, n) fo(j, 1, k) cin >> u[i][j];
    int ans = 0;
    int clear = n;
    while(1)
    {
        int cancel = 0;
        fo(i, 1, k)
        {
            if (q[i].size())
            {
                auto [val, x] = q[i].top();
                if (p[i] >= val)
                    cnt[x]--, q[i].pop();
                else
                    cancel++;
                if (cnt[x] == 0)
                {
                    ans++;
                    fo(j, 1, k) p[j] += u[x][j];
                }
            }
            else
                cancel++;
        }
        if (cancel == k)
            return cout << ans, 0;
    }
}

Compilation message (stderr)

Main.cpp:52:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   52 | main()
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:79:9: warning: unused variable 'clear' [-Wunused-variable]
   79 |     int clear = n;
      |         ^~~~~
Main.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen(name ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:58:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |         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...