'commit'
This commit is contained in:
32
TangDou/LanQiaoBei/LanQiao14GuoSai/5_1.cpp
Normal file
32
TangDou/LanQiaoBei/LanQiao14GuoSai/5_1.cpp
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
const int N = 500010;
|
||||
int f[N][2];
|
||||
int a[N];
|
||||
|
||||
int main() {
|
||||
freopen("5.in", "r", stdin);
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++) cin >> a[i];
|
||||
/*
|
||||
8
|
||||
1 2 8 3 3 4 4 5
|
||||
|
||||
10
|
||||
8 1 1 2 3 4 5 6 7 8
|
||||
*/
|
||||
// 1、处理f[i][1]
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (a[i] == a[i - 1]) f[i][1] = a[i] + 1;
|
||||
if (a[i] == f[i - 1][1]) f[i][1] = a[i] + 1;
|
||||
}
|
||||
|
||||
// 2、处理f[i][0]
|
||||
for (int i = 1; i <= n; i++) f[i][0] = max({a[i], f[i - 1][0], f[i - 1][1]});
|
||||
|
||||
cout << max(f[n][0], f[n][1]) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user