| Run ID | Author | Problem | Lang | Verdict | Score | Time | Memory | Code Length | Submit Time |
|---|---|---|---|---|---|---|---|---|---|
| 139292 | 吴晨曦 | 摆动序列 | C++ | Accepted | 100 | 0 MS | 252 KB | 632 | 2024-03-23 00:21:51 |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 005; int a[N]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; if (n <= 2) { cout << n << endl; return 0; } int res = 1, u = 1, d = 2, s = 0; for (int i = 2; i <= n; i++) { if (i == 2) { if (a[i] > a[i - 1]) { s = d; res++; } else if (a[i] < a[i - 1]) { s = u; res++; } } else if (s == u) { if (a[i] > a[i - 1]) { s = d; res++; } } else if (s == d) { if (a[i] < a[i - 1]) { s = u; res++; } } } cout << res << endl; return 0; }