Submission #810761

#TimeUsernameProblemLanguageResultExecution timeMemory
810761vjudge1코알라 (JOI13_koala)C++14
100 / 100
161 ms16052 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...