Submission #816989

# Submission time Handle Problem Language Result Execution time Memory
816989 2023-08-09T08:13:07 Z 박영우(#10128) Game (APIO22_game) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 101010
#define MAXS 20
#define INF 1000000000
#define bb ' '
#define ln '\n'
#define Ln '\n'
#define MOD 1000000007
vector<pii> ant, sugar;
ll dp[MAX];
ll psum[MAX];
int Q, L;
void solve() {
	int N = ant.size();
	int M = sugar.size();
	if (!N || !M) {
		cout << 0 << ln;
		return;
	}
	sort(ant.begin(), ant.end());
	sort(sugar.begin(), sugar.end());
	int i, j;
	for (i = 0; i < M; i++) psum[i] = sugar[i].second;
	for (i = 1; i < M; i++) psum[i] += psum[i - 1];
	for (i = 0; i < N; i++) dp[i] = 0;
	ll mn = 0;
	ll sum = 0;
	for (i = 0; i < N; i++) {
		sum += ant[i].second;
		int ind = upper_bound(sugar.begin(), sugar.end(), pii(ant[i].first + L + 1, 0)) - sugar.begin() - 1;
		int ind2 = lower_bound(sugar.begin(), sugar.end(), pii(ant[i].first - L, 0)) - sugar.begin();
		dp[i] = -ant[i].second;
		for (j = ind2; j <= ind; j++) dp[i] += sugar[j].second;
		for (j = 0; j < i; j++) {
			int ind3 = lower_bound(sugar.begin(), sugar.end(), pii(ant[j].first + L + 1, 0)) - sugar.begin();
			int l = max(ind2, ind3);
			if (l > 0) dp[i] = min(dp[i], dp[j] - ant[i].second + (psum[ind] - psum[l - 1]));
			else dp[i] = min(dp[i], dp[j] - ant[i].second + psum[ind]);
		}
		mn = min(mn, dp[i]);
	}
	cout << mn + sum << ln;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> Q >> L;
	int t, x, a;
	while (Q--) {
		cin >> t >> x >> a;
		if (t == 1) ant.emplace_back(x, a);
		else sugar.emplace_back(x, a);
		solve();
	}
}

Compilation message

/usr/bin/ld: /tmp/cc25CIrl.o: in function `main':
stub.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccMq8W3i.o:game.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cc25CIrl.o: in function `main':
stub.cpp:(.text.startup+0x64): undefined reference to `init(int, int)'
/usr/bin/ld: stub.cpp:(.text.startup+0xda): undefined reference to `add_teleporter(int, int)'
collect2: error: ld returned 1 exit status