Submission #1269883

#TimeUsernameProblemLanguageResultExecution timeMemory
1269883tungtungsahurTopical (NOI23_topical)C++17
0 / 100
1095 ms7612 KiB
#include<bits/stdc++.h>
#define ll long long
#define dn cout << "\n";
#define bit(i, j) ((i >> j) & 1)
#define F first
#define S second
#define name "task"
#define con(x) __buildtin_popcount(x)
#define sz(x) (int)(x.size())
#define pb push_back
using namespace std;
const int M = 1e6 + 2;
const int N = 250002;
const int BL = 320;
const ll MOD = 1e9 + 7;
const ll oo = 2e15;

int n, k, rs = 0;
void solve(){
    cin >> n >> k;
    vector<int> pos(k + 1, -1), st(n + 1, 0), cur;
    vector<vector<pair<int,int>>> vec(k + 1, vector<pair<int,int>> {});
    vector<vector<int>> p(n + 1, vector<int> (k + 1));
    vector<bool> used(n + 1, 0);
    for(int i = 1; i <= n; i ++){
        cur.pb(0);
        for(int j = 1; j <= k; j ++){
            int x; cin >> x;
            vec[j].pb({x, i});
        }
    }
    for(int i = 1; i <= n; i ++){
        for(int j = 1; j <= k; j ++)
            cin >> p[i][j];
    }
    for(int j = 1; j <= k; j ++){
        sort(vec[j].begin(), vec[j].end());
    }
    while(1){
        bool appear = 0;
        for(int j = 1; j <= k; j ++){
            while(cur[j - 1] >= vec[j][pos[j]+1].F){
                st[vec[j][pos[j]+1].S] ++;
                pos[j] ++;
            }
        }
        for(int i = 1; i <= n; i ++){
            if(!used[i] && st[i] == k){
                appear = 1; rs ++;
                for(int j = 1; j <= k; j ++)
                    cur[j - 1] += p[i][j];
                used[i] = 1;
            }
        }
        if(appear == 0) break;
    }
    cout << rs;
}
main(){
    cin.tie(0) -> ios::sync_with_stdio(0);
    if(fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
        freopen(name".out","w",stdout);
    }
    solve();
}
/*
Test :
4 3
5 1 0
0 1 5
0 0 0
7 7 7
0 5 6
1 1 1
8 2 0
8 1 4
Output :
4
*/

Compilation message (stderr)

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