Submission #1330827

#TimeUsernameProblemLanguageResultExecution timeMemory
1330827stephitTopical (NOI23_topical)C++20
0 / 100
1 ms356 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fi first
#define se second
#define debug cout << "NO ERROR", exit(0)
const int mod = 1e9 + 7;
const int base = 311;
const int inf = INT_MAX;
const long long inff = LLONG_MAX;
const int d4x[4] = {-1, 1, 0, 0};
const int d4y[4] = {0, 0, 1, -1};
const char c4[4] = {'U', 'D', 'R', 'L'};
const int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

const int N = 1e6 + 1;
int idx[N], cnt[N];
ll cur[N];

void DoTest() {
	int n, k; cin >> n >> k;
	vector<vector<pair<int, int>>> r(k);
	vector<vector<int>> u(k, vector<int>(n));
	vector<int> q;
	for (int i = 0; i < n; i++) {
		bool check = 1;
		vector<int> t(k);
		for (int j = 0; j < k; j++) {
			cin >> t[j];
			if (t[j] != 0) check = 0;
		}
		if (check) q.push_back(i);
		else {
			for (int j = 0; j < k; j++) r[j].push_back({t[j], i});
		}
	}

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

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

	int ans = 0;
	while (!q.empty()) {
		int i = q.back(); q.pop_back();
		ans++;
		for (int j = 0; j < k; j++) {
			cur[j] += u[j][i];
			while (idx[j] < n && r[j][idx[j]].fi <= cur[j]) {
				int tmp = r[j][idx[j]].se;
				cnt[tmp]++;
				if (cnt[tmp] == k) {
					q.push_back(idx[j]);
				}
				idx[j]++;
			}
		}
	}

	cout << ans;
}

signed main() {
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#else
		#define TASK ""
		if (TASK[0]) {
		freopen(TASK".inp", "r", stdin);
		freopen(TASK".out", "w", stdout);
		}
	#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int test = 1;
	//cin >> test;
	for (int _ = 1; _ <= test; _++) DoTest();
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:74:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |                 freopen(TASK".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:75:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |                 freopen(TASK".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...