暴力出奇迹,打表得省一,骗分过样例,考场不懵逼,多测不清空,保龄两行泪
2022 8 11 第一道蓝题祭
2023 1 29 第一道紫题祭
2023 2 06 通过200道祭
2023 7 18 第一道黑题祭
2023 8 7 橙名祭
2023 11 16 蓝题100祭
2023 11 18 退役祭
2023 12 3 差点趋势
2023 12 11 绿名祭
2023 12 13 差点退役记
2024 1 6 紫题100祭
2024 1 8 我怎么又橙名了???
#include <bits/stdc++.h>
int num[51000];
int d[51000], len, n;
int front[51000], behind[51000];
int main() {
std::cin >> n;
for (int i = 1; i <= n; ++ i) {
std::cin >> num[i];
}
len = 1, d[len] = num[1], front[1] = 1;
for (int i = 2; i <= n; ++ i) {
if (d[len] <= num[i]) d[++ len] = num[i];
else {
int temLen = std::lower_bound(d + 1, d + 1 + len, num[i]) - d;
d[temLen] = num[i];
}
front[i] = len;
// std::cout << len << " ";
}
std::cout << std::endl;
len = 1, d[len] = num[n];
for (int i = n - 1; i >= 1; -- i) {
if (d[len] <= num[i]) {
d[++len] = num[i];
behind[i] --;
}
else {
int temLen = std::lower_bound(d + 1, d + 1 + len, num[i]) - d;
d[temLen] = num[i];
}
behind[i] += len;
// std::cout << len << " ";
}
// std::cout << std::endl;
// std::cout << len << std::endl;
int answer = 0;
for (int i = 1; i <= n; ++ i) {
// std::cout << front[i] << " " << behind[i] << std::endl;
answer = std::max(answer, front[i] + behind[i]);
}
// std::cout << len << std::endl;
std::cout << n - answer;
return 0;
}
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int a1,b,c;
int h[17810],a[17801][2];
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while ( ch < '0' || ch > '9' ) {
if ( ch == '-' ) f = -1;
ch = getchar();
}
while ( ch >= '0' && ch <= '9' ) {
x = ( x << 1 ) + ( x << 3 ) + ( ch -'0' );
ch = getchar();
}
return x * f;
}
void print( int x ) {
if ( x < 0 ) putchar( '-' ), x *= -1;
if ( x > 9 ) print( x / 10 );
putchar( x % 10 + '0' );
return;
}
int main()
{
a1 = read();
for(int i=1;i<=a1;i++){
h[i] = read();
}
for(int i=1;i<=a1;i++){
a[i][0]=1;
for(int j=1;j<i;j++){
if(h[i]>=h[j]){
a[i][0]=max(a[i][0],a[j][0]+1);
}
}
}
for(int i=1;i<=a1;i++){
a[i][1]=1;
for(int j=1;j<i;j++){
if(h[j]>=h[i]){
a[i][0]=max(a[i][0],max(a[j][0],a[j][1])+1);
}
}
}
for(int i=1;i<=a1;i++){
b=max(b,max(a[i][0],a[i][1]));
}
cout<<a1-b<<endl;
//fclose(stdin);
//fclose(stdout);
return 0;
}