답안 #810740

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
810740 2023-08-06T14:46:52 Z thefless 코알라 (JOI13_koala) C++14
0 / 100
80 ms 7448 KB
#include<bits/stdc++.h>
using namespace std;
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define Times (1.0 * clock() / CLOCKS_PER_SEC)
#define fi first
#define base 31
#define sz(x) (int)(x).size()
#define se second
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define all(x) (x).begin(), (x).end()

#define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); freopen(name".bug", "w", stderr); }
#define task "name" 
#define tsk "" 

const int oo = 1e9 + 7;
const ll loo = (ll)1e18 + 7;
const int MOD = 1e9 + 7;
const int MOD2 = 1e9 + 696969;
const int N = 3e5 + 3;
const int BASE = 10;

template <typename T1, typename T2> bool minimize(T1 &a, T2 b){if (a > b) {a = b; return true;} return false;}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b){if (a < b) {a = b; return true;} return false;}

ll n , m , k , d , a , t[N] , b[N] , pre[N] , dp[N] , p[N] , vt[N];
ll st[N << 2];
vector<int> nen;

void update(int id , int l , int r , int i , int val){
	if(l == r) return void(maximize(st[id] , val));
	int mid = l + r >> 1;
	if(i <= mid) update(id << 1 , l , mid , i , val);
	if(mid + 1 <= i) update(id << 1 | 1 , mid + 1 , r , i , val);
	st[id] = max(st[id << 1] , st[id << 1 | 1]);
}

ll get(int id , int l , int r , int u , int v){
	if(l > v || r < u) return -loo;
	if(u <= l && r <= v) return st[id];
	int mid = l + r >> 1;
	return max(get(id << 1 , l , mid , u , v) , get(id << 1 | 1 , mid + 1 , r , u , v));
}

void Solve(){
	cin >> k >> m >> d >> a >> n;
	t[0] = k;
	p[0] = k % d;
	t[n + 1] = m;
	p[n + 1] = m % d;
	memset(dp , -0x3f , sizeof dp);
	dp[0] = 0;
	int cnt = 0;
	for(int i = 1 ; i <= n ; i++){
		cin >> t[i] >> b[i];
		p[i] = t[i] % d;
		// nen.pb(t[i]);
		nen.pb(p[i]);
	}
	nen.pb(p[n + 1]);
	nen.pb(p[0]);
	sort(all(nen));
	nen.erase(unique(all(nen)) , nen.end());
	for(auto v : nen) vt[v] = ++cnt;
	for(int i = 1 ; i <= n + 1 ; i++){
		dp[i] = dp[0] - (t[i] / d - t[0] / d + (p[i] > p[0])) * a + b[i];	
		maximize(dp[i] , get(1 , 1 , n + 400, vt[p[i]] , vt[p[i]]) - (t[i] / d) * a + b[i]);
		maximize(dp[i] , get(1 , 1 , n + 400 , 1 , vt[p[i]] - 1) - (t[i] / d + 1) * a + b[i]);
		maximize(dp[i] , get(1 , 1 , n + 400 , vt[p[i]] + 1 , n + 400) - (t[i] / d) * a + b[i]);
		update(1 , 1 , n + 400 , p[i] , dp[i] + (t[i] / d) * a);
	}
	cout << dp[n + 1];
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    // file(task);
    // file(tsk);
    int T = 1;
    // cin >> T;
    while(T--)
    {
        Solve();
    }
    cerr << "Time elapsed: " << Times << " s.\n";
    return 0;
}

Compilation message

koala.cpp: In function 'void update(int, int, int, int, int)':
koala.cpp:36:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |  int mid = l + r >> 1;
      |            ~~^~~
koala.cpp: In function 'long long int get(int, int, int, int, int)':
koala.cpp:45:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |  int mid = l + r >> 1;
      |            ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 6620 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 5624 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 80 ms 7448 KB Output isn't correct
2 Halted 0 ms 0 KB -