Submission #639343

#TimeUsernameProblemLanguageResultExecution timeMemory
639343LeticiaFCSK blocks (IZhO14_blocks)C++17
53 / 100
1083 ms2804 KiB
#include "bits/stdc++.h" #define st first #define nd second using lint = long long; constexpr int MOD = int(1e9) + 7; constexpr int INF = 0x3f3f3f3f; constexpr int NINF = 0xcfcfcfcf; constexpr lint LINF = 0x3f3f3f3f3f3f3f3f; const long double PI = acosl(-1.0); // Returns -1 if a < b, 0 if a = b and 1 if a > b. int cmp_double(double a, double b = 0, double eps = 1e-9) { return a + eps > b ? b + eps > a ? 0 : 1 : -1; } using namespace std; //21+18+14 pts lint dp[102][100002]; lint a[100002]; lint max_suf[100002], min_dp_menos1[100002], min_dp_mais_max[100002]; int n, k; void init(){ for(int qtd = 0; qtd <= k; qtd++) for(int i=0; i<=n; i++) dp[qtd][i] = LINF; dp[0][0] = 0; } lint naive_max(int i, int j){ lint val = a[i]; for(int k=i; k<= j; k++) val = max(val, a[k]); return val; } void print(int qtd, int i){ //cout<<"dp["<<qtd<<"]["<<i<<"] = "<<dp[qtd][i]<<"\n"; } int main() { cin.tie(nullptr)->sync_with_stdio(false); cin>>n>>k; init(); for(int i=1; i<= n; i++) cin>>a[i]; for(int qtd=1; qtd <=k; qtd++){ max_suf[0] = a[1]; if(qtd == 1) min_dp_menos1[0] = 0; else min_dp_menos1[0] = LINF; min_dp_mais_max[0] = min_dp_menos1[0] + max_suf[0]; // 0 -- i for(int i=1; i <= n; i++){ for(int j = i-1; j >=0; j--) dp[qtd][i] = min(dp[qtd][i], min_dp_mais_max[j]); print(qtd, i); max_suf[i] = a[i + 1]; min_dp_menos1[i] = dp[qtd-1][i]; min_dp_mais_max[i] = min_dp_menos1[i] + max_suf[i]; for(int j = i-1; j >=0; j--){ max_suf[j] = max(max_suf[j], max_suf[j+1]); min_dp_menos1[j] = min(min_dp_menos1[j], min_dp_menos1[j+1]); min_dp_mais_max[j] = min_dp_menos1[j] + max_suf[j]; min_dp_mais_max[j] = min(min_dp_mais_max[j], min_dp_mais_max[j+1]); } } } cout<<dp[k][n]<<"\n"; return 0; } /* [ ]Leu o problema certo??? [ ]Ver se precisa de long long [ ]Viu o limite dos fors (é n? é m?) [ ]Tamanho do vetor, será que é 2e5 em vez de 1e5?? [ ]Testar sample [ ]Testar casos de borda [ ]1LL no 1LL << i [ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?) */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...