Submission #810760

# Submission time Handle Problem Language Result Execution time Memory
810760 2023-08-06T15:02:40 Z thefless 코알라 (JOI13_koala) C++14
100 / 100
177 ms 17916 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 = 2e5 + 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] , p[N];
map<int , int> vt;
vector<ll> nen , dp(N + 1 , -loo) , st((N << 2) + 400 , -loo);

void update(int id , int l , int r , int i , ll val){
	if(l > i || r < i) return;
	if(l == r) return void(maximize(st[id] , val));
	int mid = l + r >> 1;
	update(id << 1 , l , mid , i , val);
	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;
	int cnt = 0;
	for(int i = 1 ; i <= n ; i++){
		cin >> t[i] >> b[i];
		p[i] = t[i] % d;
	}
	for(int i = 0 ; i <= n + 1 ; i++){
		nen.pb(p[i]);
	}
	sort(all(nen));
	nen.erase(unique(all(nen)) , nen.end());
	for(auto v : nen) vt[v] = ++cnt;
	dp[0] = 0;
	for(int i = 1 ; i <= n + 1 ; i++){
		dp[i] = dp[0] - ((t[i] - t[0] + d - 1) / d) * a + b[i];	
		maximize(dp[i] , get(1 , 1 , n + 30, vt[p[i]] , vt[p[i]]) - (t[i] / d) * a + b[i]);
		maximize(dp[i] , get(1 , 1 , n + 30 , 1 , vt[p[i]] - 1) - (t[i] / d + 1) * a + b[i]);
		maximize(dp[i] , get(1 , 1 , n + 30 , vt[p[i]] + 1 , n + 30) - (t[i] / d) * a + b[i]);
		update(1 , 1 , n + 30 , vt[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, long long int)':
koala.cpp:37:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |  int mid = l + r >> 1;
      |            ~~^~~
koala.cpp: In function 'long long int get(int, int, int, int, int)':
koala.cpp:46:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |  int mid = l + r >> 1;
      |            ~~^~~
koala.cpp: In function 'int main()':
koala.cpp:16:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); freopen(name".bug", "w", stderr); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:81:5: note: in expansion of macro 'file'
   81 |     file(task);
      |     ^~~~
koala.cpp:16:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); freopen(name".bug", "w", stderr); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:81:5: note: in expansion of macro 'file'
   81 |     file(task);
      |     ^~~~
koala.cpp:16:125: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); freopen(name".bug", "w", stderr); }
      |                                                                                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:81:5: note: in expansion of macro 'file'
   81 |     file(task);
      |     ^~~~
koala.cpp:16:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); freopen(name".bug", "w", stderr); }
      |                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:82:5: note: in expansion of macro 'file'
   82 |     file(tsk);
      |     ^~~~
koala.cpp:16:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); freopen(name".bug", "w", stderr); }
      |                                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:82:5: note: in expansion of macro 'file'
   82 |     file(tsk);
      |     ^~~~
koala.cpp:16:125: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 | #define file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); freopen(name".bug", "w", stderr); }
      |                                                                                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:82:5: note: in expansion of macro 'file'
   82 |     file(tsk);
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8320 KB Output is correct
2 Correct 5 ms 8196 KB Output is correct
3 Correct 5 ms 8276 KB Output is correct
4 Correct 4 ms 8148 KB Output is correct
5 Correct 4 ms 8196 KB Output is correct
6 Correct 4 ms 8148 KB Output is correct
7 Correct 4 ms 8180 KB Output is correct
8 Correct 5 ms 8232 KB Output is correct
9 Correct 5 ms 8188 KB Output is correct
10 Correct 5 ms 8180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 13396 KB Output is correct
2 Correct 69 ms 13312 KB Output is correct
3 Correct 33 ms 11472 KB Output is correct
4 Correct 74 ms 13688 KB Output is correct
5 Correct 40 ms 11276 KB Output is correct
6 Correct 26 ms 10328 KB Output is correct
7 Correct 55 ms 12544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 16072 KB Output is correct
2 Correct 177 ms 17736 KB Output is correct
3 Correct 147 ms 17900 KB Output is correct
4 Correct 146 ms 17916 KB Output is correct
5 Correct 97 ms 14040 KB Output is correct
6 Correct 70 ms 12472 KB Output is correct