제출 #1327954

#제출 시각아이디문제언어결과실행 시간메모리
1327954stephitTopical (NOI23_topical)C++20
12 / 100
124 ms20144 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;
using arr = pair<vector<int>, vector<int>>;
arr a[N];
vector<int> S[N];
int n, k;

bool smaller(const vector<int> &A, const vector<int> &B) {
	for (int i = 0; i < k; i++) {
		if (A[i] > B[i]) return 0;
	}
	return 1;
}

bool cmp(const arr &A, const arr &B) {
	return smaller(A.fi, B.fi);
}

void DoTest() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			int x; cin >> x;
			a[i].fi.push_back(x);
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			int x; cin >> x;
			a[i].se.push_back(x);
		}
	}
	sort(a + 1, a + n + 1, cmp);

//	for (int i = 1; i <= n; i++) {
//		for (int j = 0; j < k; j++) cout << a[i].fi[j] << ' ';
//		for (int j = 0; j < k; j++) cout << a[i].se[j] << ' ';
//		cout << '\n';
//	}

	for (int j = 0; j < k; j++) S[0].push_back(0);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < k; j++) S[i].push_back(S[i - 1][j] + a[i].se[j]);
	}

	vector<int> cur(k, 0);
	int prv = 0;
	int cnt = 0;

	while (1) {
		int left = prv + 1, right = n, mid, res = -1;
		while (left <= right) {
			mid = left + right >> 1;
			if (smaller(a[mid].fi, cur)) res = mid, left = mid + 1;
			else right = mid - 1;
		}
		//cout << prv << ' ' << res << '\n';
		if (res == -1) break;
		for (int j = 0; j < k; j++) cur[j] += S[res][j] - S[prv][j];
		cnt += res - prv;
		prv = res;
		//cout << res - prv << '\n' ;
		if (res == n) break;
	}

	cout << cnt;
}

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();
}

컴파일 시 표준 에러 (stderr) 메시지

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