Submission #1102361

#TimeUsernameProblemLanguageResultExecution timeMemory
1102361tuannmTopical (NOI23_topical)C++17
100 / 100
474 ms71336 KiB
#include<bits/stdc++.h>
#define ii pair<int, int>
#define ll pair<long long, long long>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod[2] = {1000000007, 998244353};
const int N = 1e6 + 1;
const string NAME = "";
int n, k;
vector<vector<ii>> r;
vector<vector<int>> u;
vector<int> cur, cnt;
vector<long long> p;

void inp(){
    cin >> n >> k;
}

void solve(){
    r.resize(k);
    u.resize(n, vector<int> (k));
    p.resize(k, 0);
    cur.resize(k, 0);
    cnt.resize(n, 0);

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < k; ++j){
            int x;
            cin >> x;

            r[j].pb({x, i});
        }

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

    int ans = 0;

    for(int i = 0; i < k; ++i)
        sort(r[i].begin(), r[i].end());

    while(1){
        vector<int> can_complete;

        for(int i = 0; i < k; ++i){
            while(cur[i] < n && r[i][cur[i]].fi <= p[i]){
                ++cnt[r[i][cur[i]].se];

                if(cnt[r[i][cur[i]].se] == k)
                    can_complete.pb(r[i][cur[i]].se);

                ++cur[i];
            }
        }

        if(can_complete.empty())
            break;

        ans += can_complete.size();

        for(int i : can_complete)
            for(int j = 0; j < k; ++j)
                p[j] += u[i][j];
    }

    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    if(fopen((NAME + ".inp").c_str(), "r")){
        freopen((NAME + ".inp").c_str(), "r", stdin);
        freopen((NAME + ".out").c_str(), "w", stdout);
    }

    inp();
    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((NAME + ".inp").c_str(), "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((NAME + ".out").c_str(), "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...