QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#165877 | #5507. Investors | arseny_y# | WA | 2ms | 3508kb | C++23 | 1.7kb | 2023-09-05 22:30:05 | 2023-09-05 22:30:06 |
Judging History
answer
//I wrote this code 4 u today
#include <bits/stdc++.h>
template<class t> using vc = std::vector<t>;
#define nd node*
#define pnd pair<nd, nd>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vc<pll> vpll;
typedef vc<vll> vvll;
typedef vc<vpll> vvpll;
template<const ll MOD>
struct mod_mul : std::multiplies<const ll> {
ll operator()(const ll a, const ll b) {
return (a * b) % MOD;
}
};
template<typename T>
inline void sort(T &a) {
sort(a.begin(), a.end());
}
template<typename T>
inline void unique(T &a) {
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template<typename T>
inline void reverse(T &a) {
reverse(a.begin(), a.end());
}
const ll INF = 9023372036854775808ll;
const ll MOD = 1000000007ll;
int main() {
cin.tie(nullptr)->ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vc<int> a(n);
for (auto &i: a) cin >> i;
k = min(k, k - 1);
a.insert(a.begin(), 0);
vc<vc<int>> dp(n + 2, vc<int>(n + 2, INF));
vc<vc<int>> cnt(n + 2, vc<int>(n + 2));
for (int i = 1; i <= n; ++i) for (int j = i, now = 0; j >= 1; --j) {
cnt[j][i] = cnt[j][i - 1] + (now += (a[i] < a[j]));
}
for (int i = 1; i <= n; ++i) dp[i][0] = cnt[1][i];
for (int i = 0; i <= k; ++i) dp[0][i] = 0;
for (int i = 2; i <= n; ++i) {
for (int c = 1; c <= k; ++c) {
for (int j = 0; j < i; ++j) {
dp[i][c] = min(dp[j][c - 1] + cnt[j + 1][i], dp[i][c]);
}
}
}
cout << dp[n][k] << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3508kb
input:
2 6 1 4 5 6 2 2 1 6 2 4 5 6 2 2 1
output:
11 2
result:
wrong answer 1st lines differ - expected: '2', found: '11'