Submission #100815

# Submission time Handle Problem Language Result Execution time Memory
100815 2019-03-14T15:53:28 Z 1Khan K blocks (IZhO14_blocks) C++14
0 / 100
1000 ms 896 KB
// In the name of GOD

#include <bits/stdc++.h>

using namespace std;

#define BeGood ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define nl '\n'
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;
typedef double db;

const int N = 1e5 + 101;
const int M = 1e9 + 7;
const int d = 20;

int n, k, a[N];
vector<int> ans;
int dp[d][N];
int ANS = M;
void man(int id, int sum, int len){
     if(sum > n){
          return;
     }
     if(id > k){
          if(sum == n){
               int answer = 0;
               int l = 1;
               int r = 0;
               for(int i = 0; i < sz(ans); ++i){
                    int res = 0;
                    r += ans[i];
                    int L = l;
                    int R = r;
                    L--;
                    R--;
                    for(int j = d; j >= 0; --j){
                         if(L + (1 << j) - 1 <= R){
                              res = max(res, dp[j][L]);
                              L += 1 << j;
                         }
                    }
                    answer += res;
                    l = r + 1;
               }
               ANS = min(ANS, answer);
          }
          return;
     }
     for(int i = 1; i <= len; ++i){
          ans.pb(i);
          sum += i;
          int newlen = n - sum - id + 1;
          man(id + 1, sum, newlen);
          sum -= i;
          ans.pop_back();
     }
}
int main(){

     BeGood

     cin >> n >> k;
     for(int i = 0; i < n; ++i){
          cin >> a[i];
          dp[0][i] = a[i];
     }
     for(int i = 1; i <= d; ++i){
          for(int j = 0; j <= n - (1 << i); ++j){
               dp[i][j] = max(dp[i - 1][j], dp[i - 1][j + (1 << (i - 1))]);
          }
     }
     man(1, 0, n - k + 1);
     cout << ANS;
     return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 2 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 256 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Incorrect 3 ms 384 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 896 KB Time limit exceeded
2 Halted 0 ms 0 KB -