0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 14:36:27 +00:00

1584. [Usaco2009 Mar]Cleaning Up 打扫卫生

https://hydro.ac/d/bzoj/record/6322ef85bdf9bc31d160a35f
This commit is contained in:
Baoshuo Ren 2022-09-15 17:25:46 +08:00
parent 0317384c93
commit a4335d561f
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 113 additions and 0 deletions

53
BZOJ/1584/1584.cpp Normal file
View File

@ -0,0 +1,53 @@
#include <iostream>
#include <cmath>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 40005;
int n, m, t, p[N], pre[N], lst[N], nxt[N], pos[N], cnt[N], f[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> m;
std::fill(f, f + 1 + n, 0x3f3f3f3f);
for (int i = 1; i <= n; i++) {
cin >> p[i];
pre[i] = lst[p[i]];
nxt[lst[p[i]]] = i;
lst[p[i]] = i;
nxt[i] = n + 1;
}
t = std::sqrt(n);
f[1] = 1;
for (int i = 1; i <= t; i++) {
pos[i] = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= t; j++) {
if (pre[i] < pos[j]) cnt[j]++;
if (cnt[j] > j) {
cnt[j]--;
while (nxt[pos[j]++] < i) {}
}
f[i] = std::min(f[i], f[pos[j] - 1] + (int)std::pow(j, 2));
}
}
cout << f[n] << endl;
return 0;
}

BIN
BZOJ/1584/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/1584/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.