Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
112101 曾煦翔 合唱队形 C++ 通过 100 0 MS 652 KB 766 2023-11-25 10:20:41

Tests(10/10):


#include <bits/stdc++.h> using namespace std; const int M = 1e5 + 5, INF = 1e9; int a[M], f1[M], f2[M], g[M], len, ans = -INF; int main() { int n; scanf ("%d", &n); for (int i = 1; i <= n; i++) scanf ("%d", &a[i]); len = 0; for (int i = 1; i <= n; i++) { int pos = lower_bound(g + 1, g + len + 1, a[i]) - g; f1[i] = pos; g[pos] = a[i]; len = max(len, pos); } len = 0; memset(g, 0, sizeof g); for (int i = n; i >= 1; i--) { int pos = lower_bound(g + 1, g + len + 1, a[i]) - g; f2[i] = pos; g[pos] = a[i]; len = max(len, pos); } for (int i = 1; i <= n; i++) ans = max(ans, f1[i] + f2[i] - 1); cout << n - ans; return 0; }


测评信息: