Submission #253613

# Submission time Handle Problem Language Result Execution time Memory
253613 2020-07-28T13:02:33 Z Red_Inside K blocks (IZhO14_blocks) C++17
0 / 100
13 ms 9856 KB
#include <bits/stdc++.h>
#include <random>

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using namespace std;
const ll maxn=1e5+100, inf=1e9,LOG=18,mod=1e9+7;
ll block = 300, timer = 0;
const ld EPS = 1e-7;

#define bt(i) (1 << (i))
//#define int ll
#define y1 yy
#define pii pair <int, int>

int n, k, a[maxn], step[maxn], opt[maxn][110], dp[maxn][110];
int parse[maxn][LOG];

int calc(int l, int r)
{
	int len = r - l + 1;
	//7 8 9 10 11
	return max(parse[l][step[len]], parse[r - (1 << step[len]) + 1][step[len]]);
}

main()
{
	IOS
	cin >> n >> k;
	step[1] = 0;
	forn(2, i, n)
	{
		step[i] = step[i - 1];
		if((1 << (step[i] + 1)) <= i)
		{
			step[i]++;
		}
	}
	forn(1, i, n)
	{
		cin >> a[i];
		parse[i][0] = a[i];
	}
	forn(1, j, LOG - 1)
	{
		forn(1, i, n)
		{
			if(i + (1 << (j - 1)) <= n)
				parse[i][j] = max(parse[i][j - 1], parse[i + (1 << (j - 1))][j - 1]);
			else
				parse[i][j] = parse[i][j - 1];
		}
	}
	forn(1, j, k)
	{
		opt[n + 1][j] = n - 1;
	}
	//dp[i][j]
	//opt[i][j - 1] <= opt[i][j] <= opt[i + 1][j]
	forn(1, j, k)
	{
		forn(0, i, n)
		{
			dp[i][j] = inf;
		}
	}
	forn(1, j, k)
	{
		nfor(j, i, n)
		{
			dp[i][j] = inf;
			forn(opt[i][j - 1], dot, opt[i + 1][j])
			{
				if(dp[dot][j - 1] + calc(dot + 1, i) < dp[i][j])
				{
					dp[i][j] = dp[dot][j - 1] + calc(dot + 1, i);
					opt[i][j] = dot;
				}
			}
//			cout << i << " " << j << " " << dp[i][j] << " " << opt[i][j] << " " << endl;
		}
	}
	cout << dp[n][k];
}

Compilation message

blocks.cpp:45:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 9856 KB Output isn't correct
2 Halted 0 ms 0 KB -