Submission #444688

# Submission time Handle Problem Language Result Execution time Memory
444688 2021-07-14T20:19:45 Z NaimSS K blocks (IZhO14_blocks) C++14
53 / 100
128 ms 175564 KB
#include <bits/stdc++.h>
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define Unique(v) sort(all(v));v.erase(unique(all(v)),v.end());
#define sz(v) ((int)v.size())
using namespace std;
typedef vector<int> vi;
#define y1 abacaba
//#define left oooooopss
#define db(x) cerr << #x <<" == "<<x << endl;
#define db2(x,y) cerr<<#x <<" == "<<x<<", "<<#y<<" == "<<y<<endl;
#define db3(x,y,z) cerr << #x<<" == "<<x<<", "<<#y<<" == "<<y<<", "<<#z<<" == "<<z<<endl;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());
ll cdiv(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll fdiv(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
//inline ll mod(ll n, ll m ){ ll ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0LL ? a : gcd(b, a%b));}
ll exp(ll b,ll e,ll m){
  b%=m;
  ll ans = 1;
  for (; e; b = b * b % m, e /= 2)
      if (e & 1) ans = ans * b % m;
  return ans;
}

// debug:
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T){ 
  cerr << ' ' << H; 
  dbg_out(T...); 
}
#ifdef LOCAL
#define dbg(...) cerr<<"(" << #__VA_ARGS__<<"):" , dbg_out(__VA_ARGS__) , cerr << endl
#else
#define dbg(...)
#endif
//

const int N = 8080;
ll A[N],B[N];
ll dp[100100][110];
int32_t main(){
  fastio;
  int n,k;
  cin >> n >> k;
  rep(i,0,100100)rep(j,0,110)dp[i][j] = 1e18;
  ll mx=0;
  rep(i,1,n+1){
    cin >> A[i];
    B[i] = A[i];
    mx=max(mx,A[i]);
    dp[i][1] = mx;
  }
  sort(B+1,B+1+n,greater<ll>());


  rep(i,2,k+1){
    stack<pll> st;
    rep(j,1,n+1){
      ll val = dp[j-1][i-1];
      while(!st.empty() && st.top().ff < A[j]){
        val=min(val,st.top().ss);
        st.pop();
      }

      if(st.empty() || st.top().ff + st.top().ss > A[j] + val){
        st.push(pll(A[j],val));
      }
      if(j>=i)
        dp[j][i] = st.top().ff + st.top().ss;

    }

  }

  cout << dp[n][k] << endl;


  // math -> gcd it all
  // Did u check N=1? Did you switch N,M?
}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 86468 KB Output is correct
2 Correct 45 ms 86424 KB Output is correct
3 Correct 45 ms 86468 KB Output is correct
4 Correct 46 ms 86396 KB Output is correct
5 Correct 45 ms 86468 KB Output is correct
6 Correct 45 ms 86388 KB Output is correct
7 Correct 47 ms 86412 KB Output is correct
8 Correct 45 ms 86444 KB Output is correct
9 Correct 45 ms 86388 KB Output is correct
10 Correct 43 ms 86436 KB Output is correct
11 Correct 45 ms 86400 KB Output is correct
12 Correct 45 ms 86492 KB Output is correct
13 Correct 45 ms 86440 KB Output is correct
14 Correct 45 ms 86380 KB Output is correct
15 Correct 45 ms 86392 KB Output is correct
16 Correct 45 ms 86436 KB Output is correct
17 Correct 44 ms 86440 KB Output is correct
18 Correct 44 ms 86496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 86468 KB Output is correct
2 Correct 43 ms 86504 KB Output is correct
3 Correct 44 ms 86392 KB Output is correct
4 Correct 44 ms 86468 KB Output is correct
5 Correct 43 ms 86432 KB Output is correct
6 Correct 45 ms 86476 KB Output is correct
7 Correct 43 ms 86476 KB Output is correct
8 Correct 43 ms 86496 KB Output is correct
9 Correct 44 ms 86468 KB Output is correct
10 Correct 43 ms 86500 KB Output is correct
11 Correct 44 ms 86392 KB Output is correct
12 Correct 43 ms 86448 KB Output is correct
13 Correct 44 ms 86436 KB Output is correct
14 Correct 45 ms 86468 KB Output is correct
15 Correct 44 ms 86412 KB Output is correct
16 Correct 44 ms 86492 KB Output is correct
17 Correct 44 ms 86436 KB Output is correct
18 Correct 43 ms 86420 KB Output is correct
19 Correct 43 ms 86472 KB Output is correct
20 Correct 43 ms 86376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 86468 KB Output is correct
2 Correct 45 ms 86424 KB Output is correct
3 Correct 45 ms 86468 KB Output is correct
4 Correct 46 ms 86396 KB Output is correct
5 Correct 45 ms 86468 KB Output is correct
6 Correct 45 ms 86388 KB Output is correct
7 Correct 47 ms 86412 KB Output is correct
8 Correct 45 ms 86444 KB Output is correct
9 Correct 45 ms 86388 KB Output is correct
10 Correct 43 ms 86436 KB Output is correct
11 Correct 45 ms 86400 KB Output is correct
12 Correct 45 ms 86492 KB Output is correct
13 Correct 45 ms 86440 KB Output is correct
14 Correct 45 ms 86380 KB Output is correct
15 Correct 45 ms 86392 KB Output is correct
16 Correct 45 ms 86436 KB Output is correct
17 Correct 44 ms 86440 KB Output is correct
18 Correct 44 ms 86496 KB Output is correct
19 Correct 43 ms 86468 KB Output is correct
20 Correct 43 ms 86504 KB Output is correct
21 Correct 44 ms 86392 KB Output is correct
22 Correct 44 ms 86468 KB Output is correct
23 Correct 43 ms 86432 KB Output is correct
24 Correct 45 ms 86476 KB Output is correct
25 Correct 43 ms 86476 KB Output is correct
26 Correct 43 ms 86496 KB Output is correct
27 Correct 44 ms 86468 KB Output is correct
28 Correct 43 ms 86500 KB Output is correct
29 Correct 44 ms 86392 KB Output is correct
30 Correct 43 ms 86448 KB Output is correct
31 Correct 44 ms 86436 KB Output is correct
32 Correct 45 ms 86468 KB Output is correct
33 Correct 44 ms 86412 KB Output is correct
34 Correct 44 ms 86492 KB Output is correct
35 Correct 44 ms 86436 KB Output is correct
36 Correct 43 ms 86420 KB Output is correct
37 Correct 43 ms 86472 KB Output is correct
38 Correct 43 ms 86376 KB Output is correct
39 Correct 43 ms 86380 KB Output is correct
40 Correct 44 ms 86416 KB Output is correct
41 Correct 43 ms 86468 KB Output is correct
42 Correct 43 ms 86376 KB Output is correct
43 Correct 43 ms 86388 KB Output is correct
44 Correct 43 ms 86420 KB Output is correct
45 Correct 44 ms 86420 KB Output is correct
46 Correct 44 ms 86424 KB Output is correct
47 Correct 44 ms 86484 KB Output is correct
48 Correct 44 ms 86468 KB Output is correct
49 Correct 43 ms 86464 KB Output is correct
50 Correct 44 ms 86464 KB Output is correct
51 Correct 44 ms 86468 KB Output is correct
52 Correct 43 ms 86480 KB Output is correct
53 Correct 44 ms 86396 KB Output is correct
54 Correct 42 ms 86472 KB Output is correct
55 Correct 44 ms 86464 KB Output is correct
56 Correct 43 ms 86472 KB Output is correct
57 Correct 43 ms 86468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 86468 KB Output is correct
2 Correct 45 ms 86424 KB Output is correct
3 Correct 45 ms 86468 KB Output is correct
4 Correct 46 ms 86396 KB Output is correct
5 Correct 45 ms 86468 KB Output is correct
6 Correct 45 ms 86388 KB Output is correct
7 Correct 47 ms 86412 KB Output is correct
8 Correct 45 ms 86444 KB Output is correct
9 Correct 45 ms 86388 KB Output is correct
10 Correct 43 ms 86436 KB Output is correct
11 Correct 45 ms 86400 KB Output is correct
12 Correct 45 ms 86492 KB Output is correct
13 Correct 45 ms 86440 KB Output is correct
14 Correct 45 ms 86380 KB Output is correct
15 Correct 45 ms 86392 KB Output is correct
16 Correct 45 ms 86436 KB Output is correct
17 Correct 44 ms 86440 KB Output is correct
18 Correct 44 ms 86496 KB Output is correct
19 Correct 43 ms 86468 KB Output is correct
20 Correct 43 ms 86504 KB Output is correct
21 Correct 44 ms 86392 KB Output is correct
22 Correct 44 ms 86468 KB Output is correct
23 Correct 43 ms 86432 KB Output is correct
24 Correct 45 ms 86476 KB Output is correct
25 Correct 43 ms 86476 KB Output is correct
26 Correct 43 ms 86496 KB Output is correct
27 Correct 44 ms 86468 KB Output is correct
28 Correct 43 ms 86500 KB Output is correct
29 Correct 44 ms 86392 KB Output is correct
30 Correct 43 ms 86448 KB Output is correct
31 Correct 44 ms 86436 KB Output is correct
32 Correct 45 ms 86468 KB Output is correct
33 Correct 44 ms 86412 KB Output is correct
34 Correct 44 ms 86492 KB Output is correct
35 Correct 44 ms 86436 KB Output is correct
36 Correct 43 ms 86420 KB Output is correct
37 Correct 43 ms 86472 KB Output is correct
38 Correct 43 ms 86376 KB Output is correct
39 Correct 43 ms 86380 KB Output is correct
40 Correct 44 ms 86416 KB Output is correct
41 Correct 43 ms 86468 KB Output is correct
42 Correct 43 ms 86376 KB Output is correct
43 Correct 43 ms 86388 KB Output is correct
44 Correct 43 ms 86420 KB Output is correct
45 Correct 44 ms 86420 KB Output is correct
46 Correct 44 ms 86424 KB Output is correct
47 Correct 44 ms 86484 KB Output is correct
48 Correct 44 ms 86468 KB Output is correct
49 Correct 43 ms 86464 KB Output is correct
50 Correct 44 ms 86464 KB Output is correct
51 Correct 44 ms 86468 KB Output is correct
52 Correct 43 ms 86480 KB Output is correct
53 Correct 44 ms 86396 KB Output is correct
54 Correct 42 ms 86472 KB Output is correct
55 Correct 44 ms 86464 KB Output is correct
56 Correct 43 ms 86472 KB Output is correct
57 Correct 43 ms 86468 KB Output is correct
58 Runtime error 128 ms 175564 KB Execution killed with signal 11
59 Halted 0 ms 0 KB -