답안 #813071

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
813071 2023-08-07T13:08:42 Z vjudge1 코알라 (JOI13_koala) C++
100 / 100
79 ms 6860 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pill pair<int,ll>
#define mem(a, b) memset(a, b, sizeof(a))
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define name "test"

using namespace std;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;

template <typename T1, typename T2> bool maxi(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;}
template <typename T1, typename T2> bool mini(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;}

bool ok;

struct SEGTREE{
	ll val[N << 2];
	SEGTREE(){
		mem(val, -0x3f);
	};
	void update(int id, int l, int r, int i, ll x){
		if (l > i || r < i) return;
		if (l == r){
			val[id] = max(val[id], x);
			return;
		}
		int m = (l + r) >> 1;
		if (m >= i) update(id << 1, l, m, i, x);
		else update(id << 1 | 1, m + 1, r, i, x);
		val[id] = max(val[id << 1], val[id << 1 | 1]);
	}

	ll get(int id, int l, int r, int u, int v){
		if (l > v || r < u) return -oo;
		if (l >= u && r <= v) return val[id];
		int m = (l + r) >> 1;
		return max(get(id << 1, l, m, u, v), get(id << 1 | 1, m + 1, r, u, v));
	}
} ST;
int s, t;
int limDis, downPower, n;
int a[N];
int b[N];
ll ans = -oo;
vector <int> value;

void load(){
	cin.tie(0)->sync_with_stdio(0);
	if (fopen(name".inp", "r")){
		freopen(name".inp", "r", stdin);
		freopen(name".out", "w", stdout);
	}
}

void input(){
	cin >> s >> t >> limDis >> downPower >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
}

void solve(){
	a[0] = s;
	a[n + 1] = t;
	for (int i = 0; i <= n + 1; i++){
		int r = a[i] % limDis;
		if (r == 0) r = limDis;
		value.push_back(r);
	}
	sort(value.begin(), value.end());
	int nSeg = value.size();
	int r = s % limDis;
	ll k = (s + limDis - 1) / limDis;
	if (r == 0) r = limDis;

	int id = lower_bound(value.begin(), value.end(), r) - value.begin() + 1;

	ST.update(1, 1, nSeg, id, k * downPower);
	for (int i = 1; i <= n + 1; i++){
		int r = a[i] % limDis;
		ll k = (a[i] + limDis - 1) / limDis;
		if (r == 0) r = limDis;
		int id = lower_bound(value.begin(), value.end(), r) - value.begin() + 1;
		ll tmp1 = ST.get(1, 1, nSeg, 1, id - 1) - k * downPower -  downPower + b[i];
		ll tmp2 = ST.get(1, 1, nSeg, id, nSeg) - k * downPower + b[i];
		if (i == n + 1) maxi(ans, max(tmp1, tmp2));
		ST.update(1, 1, nSeg, id, max(tmp1, tmp2) + k * downPower);
	}
	cout << ans;
}

int main(){
	load();
	input();
	solve();
}


Compilation message

koala.cpp: In function 'void load()':
koala.cpp:58:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |   freopen(name".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:59:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   freopen(name".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3444 KB Output is correct
3 Correct 2 ms 3480 KB Output is correct
4 Correct 2 ms 3412 KB Output is correct
5 Correct 2 ms 3412 KB Output is correct
6 Correct 2 ms 3412 KB Output is correct
7 Correct 2 ms 3460 KB Output is correct
8 Correct 2 ms 3412 KB Output is correct
9 Correct 2 ms 3412 KB Output is correct
10 Correct 2 ms 3412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 6860 KB Output is correct
2 Correct 51 ms 6492 KB Output is correct
3 Correct 16 ms 5516 KB Output is correct
4 Correct 43 ms 6676 KB Output is correct
5 Correct 25 ms 5464 KB Output is correct
6 Correct 15 ms 4692 KB Output is correct
7 Correct 21 ms 5852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 6784 KB Output is correct
2 Correct 67 ms 6704 KB Output is correct
3 Correct 60 ms 6796 KB Output is correct
4 Correct 53 ms 6792 KB Output is correct
5 Correct 39 ms 5456 KB Output is correct
6 Correct 30 ms 5012 KB Output is correct