Submission #102774

# Submission time Handle Problem Language Result Execution time Memory
102774 2019-03-27T12:58:11 Z Mahmoud_Adel K blocks (IZhO14_blocks) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define s second
#define f first
typedef long long ll;
const int N = 100005, M = 105;
int n, k, a[N], dp[M][N], ch[M][N];
int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];
    memset(dp, 0x3f3f3f3f, dp);
    dp[0][0] = 0;
    for(int i=1; i<=k; i++)
    {
        stack<int> s;
        for(int j=i; j<=n; j++)
        {
            dp[i][j] = dp[i-1][j-1]+ a[j], ch[i][j] = a[j];
            while(!s.empty())
            {
                int u = s.top();
                if(a[u] <= a[j])
                {
                    if(dp[i][j] > dp[i][u] - ch[i][u] + max(ch[i][u], a[j]))
                    dp[i][j] = dp[i][u] - ch[i][u] + max(ch[i][u], a[j]), ch[i][j] = max(ch[i][u], a[j]);
                }
                else break;
                s.pop();
            }
            if(!s.empty())
            {
                int u = s.top();
                if(dp[i][u] < dp[i][j])
                {
                    dp[i][j] = dp[i][u];
                    ch[i][j] = ch[i][u];
                }
            }
            s.push(j);
        }
    }
    cout << dp[k][n] << endl;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:12:30: error: invalid conversion from 'int (*)[100005]' to 'size_t {aka long unsigned int}' [-fpermissive]
     memset(dp, 0x3f3f3f3f, dp);
                              ^
In file included from /usr/include/features.h:367:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/c++config.h:533,
                 from /usr/include/c++/7/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from blocks.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string3.h:78:1: note:   initializing argument 3 of 'void* memset(void*, int, size_t)'
 __NTH (memset (void *__dest, int __ch, size_t __len))
 ^