Submission #876870

# Submission time Handle Problem Language Result Execution time Memory
876870 2023-11-22T12:48:38 Z TAhmed33 Peru (RMI20_peru) C++17
0 / 100
31 ms 29664 KB
#include <bits/stdc++.h>
#include <peru.h>
using namespace std;
typedef long long ll;
const int MAXN = 2500000;
const int MOD = 1e9 + 7;
int add (int a, int b) {
	a += b; if (a >= MOD) a -= MOD;
	return a;
}
int sub (int a, int b) {
	a -= b; if (a < 0) a += MOD;
	return a;
}
int mul (int a, int b) {
	return (a * 1ll * b) % MOD;
}
int pw[MAXN + 25];
ll dp[MAXN + 25];
int solve (int n, int k, int *s) {
	pw[0] = 1; for (int i = 1; i < MAXN + 25; i++) {
		pw[i] = mul(i, pw[i - 1]);
	}
	int ret = 0;
	for (int i = 1; i <= n; i++) {
		int mx = s[i - 1];
		dp[i] = 1e18;
		for (int j = i - 1; j >= max(0, i - k); j++) {
			dp[i] = min(dp[i], dp[j] + mx);
			mx = max(mx, s[i - 1]);
		}
		ret = add(ret, mul(pw[n - i], dp[i] % MOD));
	}
	return ret;
}
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 29664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 29664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 29664 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -