Submission #24916

# Submission time Handle Problem Language Result Execution time Memory
24916 2017-06-17T06:03:38 Z dotorya 코알라 (JOI13_koala) C++14
100 / 100
86 ms 7564 KB
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

ll indt[300000];
void update(int p, ll v) {
	p += IT_MAX;
	indt[p] = max(indt[p], v);
	for (p /= 2; p; p /= 2) indt[p] = max(indt[2 * p], indt[2 * p + 1]);
}
ll getmx(int p1, int p2) {
	p1 += IT_MAX;
	p2 += IT_MAX;
	ll rv = -LL_INF;
	for (; p1 <= p2; p1 /= 2, p2 /= 2) {
		if (p1 % 2 == 1) rv = max(rv, indt[p1++]);
		if (p2 % 2 == 0) rv = max(rv, indt[p2--]);
	}
	return rv;
}

vector <int> Vx;
ll dp[100050];

ll in[100050][2];
int main() {
	int K, M, D, A, N, i;
	scanf("%d %d %d %d %d", &K, &M, &D, &A, &N);
	M -= K;
	for (i = 1; i <= N; i++) {
		scanf("%lld %lld", &in[i][0], &in[i][1]);
		in[i][0] -= K;
	}
	in[N + 1][0] = M;

	dp[0] = 0;
	Vx.push_back(0);
	for (i = 1; i <= N + 1; i++) Vx.push_back(in[i][0] % D);
	sort(all(Vx));
	Vx.erase(unique(all(Vx)), Vx.end());
	for (i = 1; i < 2 * IT_MAX; i++) indt[i] = -LL_INF;
	update(0, 0);
	for (i = 1; i < Vx.size(); i++) {
		update(i, -A);
	}
	
	for (i = 1; i <= N + 1; i++) {
		int p = lower_bound(all(Vx), in[i][0] % D) - Vx.begin();

		ll v = max(getmx(p, Vx.size() - 1) - (in[i][0] / D) * A, getmx(0, Vx.size() - 1) - (in[i][0] / D + 1) * A);
		dp[i] = v + in[i][1];
		update(p, dp[i] + (in[i][0] / D) * A);
	}
//	for (i = 1; i <= N + 1; i++) printf("%lld ", dp[i]);
//	printf("\n");
	return !printf("%lld\n", dp[N + 1]);
}

Compilation message

koala.cpp:23:0: warning: ignoring #pragma warning  [-Wunknown-pragmas]
 #pragma warning(disable:4996)  
 ^
koala.cpp:24:0: warning: ignoring #pragma comment  [-Wunknown-pragmas]
 #pragma comment(linker, "/STACK:336777216")  
 ^
koala.cpp: In function 'int main()':
koala.cpp:91:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (i = 1; i < Vx.size(); i++) {
                ^
koala.cpp:76:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d %d", &K, &M, &D, &A, &N);
                                             ^
koala.cpp:79:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &in[i][0], &in[i][1]);
                                           ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 6712 KB Output is correct
2 Correct 0 ms 6712 KB Output is correct
3 Correct 0 ms 6712 KB Output is correct
4 Correct 0 ms 6712 KB Output is correct
5 Correct 0 ms 6712 KB Output is correct
6 Correct 0 ms 6712 KB Output is correct
7 Correct 0 ms 6712 KB Output is correct
8 Correct 0 ms 6712 KB Output is correct
9 Correct 0 ms 6712 KB Output is correct
10 Correct 0 ms 6712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 7564 KB Output is correct
2 Correct 59 ms 7564 KB Output is correct
3 Correct 26 ms 7180 KB Output is correct
4 Correct 53 ms 7564 KB Output is correct
5 Correct 39 ms 7180 KB Output is correct
6 Correct 19 ms 7180 KB Output is correct
7 Correct 46 ms 7564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 7564 KB Output is correct
2 Correct 86 ms 7564 KB Output is correct
3 Correct 79 ms 7564 KB Output is correct
4 Correct 83 ms 7564 KB Output is correct
5 Correct 56 ms 7180 KB Output is correct
6 Correct 53 ms 7180 KB Output is correct