답안 #1108691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1108691 2024-11-04T19:11:34 Z akzytr 나일강 (IOI24_nile) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#define ve vector
#define pb push_back
#define ar array
#define ll long long
#define sz(x) (int)(x.size())
using namespace std;

ve<ll> calculate_costs(ve<int> W, ve<int> A, ve<int> B, ve<int> Q) {
	ve<ll> ans;
	int N = sz(W);
	array<ll, 2> W2[N];

	for(int i = 0; i < N; i++) {
		W2[i] = {W[i], i};
	}
	sort(W2, W2 + N);

	for(int diff : Q) {
		ll tc = 0;
		ve<ve<int>> ccs;
		ve<int> curcc;
		for(int i = 0; i < N; i++) {
			if(i != 0 && W2[i][0] - W2[i - 1][0] > diff) {
				ccs.pb(curcc);
				ve<int> nc;
				curcc = nc;
			}
			curcc.pb(i);
		}
		ccs.pb(curcc);

		for(auto i : ccs) {
			assert(sz(i) >= 1);
			ll tb = 0;
			for(int j : i) {
				int idx = W2[j][1];
				tb += B[idx];
			}

			if(sz(i) % 2) {
				int sz_cc = sz(i);
				int idxone = W2[i[0]][1];
				int idxn = W2[i[sz_cc - 1]][1];
				ll mi = 91e18;

				for(int j = 0; j < sz_cc; j++) {
					if(j % 2 == 0) {
						mi = min(mi, tb - B[idx] + A[idx]);
					} else if(W2[i[j + 1]][0] - W2[i[j - 1]][0] <= diff) {
						int idx = W2[i[j]][1];
						mi = min(mi, tb - B[idx] + A[idx]);
					}
				}

				tb = mi;
			}

			tc += tb;
		}
		ans.pb(tc);
	}

	return ans;
}

// int main() {
// 	int N;
// 	cin >> N;
//
// 	ve<int> w;
// 	ve<int> a;
// 	ve<int> b;
// 	ve<int> q;
// 	for(int i = 0; i < N; i++) {
// 		int x, y, z;
// 		cin >> x >> y >> z;
// 		w.pb(x);
// 		a.pb(y);
// 		b.pb(z);
// 	}
// 	int Q;
// 	cin >> Q;
// 	for(int i = 0; i < Q; i++) {
// 		int x;
// 		cin >> x;
// 		q.pb(x);
// 	}
//
// 	calculate_costs(w, a, b, q);
// }

Compilation message

nile.cpp: In function 'std::vector<long long int> calculate_costs(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
nile.cpp:45:13: warning: overflow in conversion from 'double' to 'long long int' changes value from '9.1e+19' to '9223372036854775807' [-Woverflow]
   45 |     ll mi = 91e18;
      |             ^~~~~
nile.cpp:49:27: error: 'idx' was not declared in this scope; did you mean 'idxn'?
   49 |       mi = min(mi, tb - B[idx] + A[idx]);
      |                           ^~~
      |                           idxn
nile.cpp:43:9: warning: unused variable 'idxone' [-Wunused-variable]
   43 |     int idxone = W2[i[0]][1];
      |         ^~~~~~
nile.cpp:44:9: warning: unused variable 'idxn' [-Wunused-variable]
   44 |     int idxn = W2[i[sz_cc - 1]][1];
      |         ^~~~