Submission #1221351
Source Code Expand
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<cassert> using namespace std; #define sz(x) (int)(x.size()) #define fi(a, b) for(int i=a;i<b;++i) #define fj(a, b) for(int j=a;j<b;++j) #define fk(a, b) for(int k=a;k<b;++k) #define pb push_back #define mp make_pair typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; //////////////// int const N = 1e5 + 41; int const INF = 1e9 + 41; int n; int a[N], d[N][2]; void solve(){ cin >> n; fi(1, n+1){ cin >> a[i]; } fi(0, N) fj(0, 2) d[i][j] = INF; d[1][0] = d[1][1] = 1; fi(2, n+1){ d[i][0] = d[i][1] = (1 + min(d[i-1][0], d[i-1][1])); if(a[i-1] <= a[i]) d[i][1] = min(d[i-1][1], d[i][1]); if(a[i-1] >= a[i]) d[i][0] = min(d[i-1][0], d[i][0]); } int ans = min(d[n][1], d[n][0]); cout << ans << endl; } int main(){ #ifdef _DEBUG freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif solve(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | A - Sorted Arrays |
User | Filyan |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 1009 Byte |
Status | AC |
Exec Time | 55 ms |
Memory | 1408 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample_01.txt, sample_02.txt, sample_03.txt |
All | sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
sample_01.txt | AC | 2 ms | 1024 KB |
sample_02.txt | AC | 2 ms | 1024 KB |
sample_03.txt | AC | 2 ms | 1024 KB |
subtask_1_01.txt | AC | 33 ms | 1280 KB |
subtask_1_02.txt | AC | 27 ms | 1152 KB |
subtask_1_03.txt | AC | 17 ms | 1152 KB |
subtask_1_04.txt | AC | 53 ms | 1408 KB |
subtask_1_05.txt | AC | 55 ms | 1408 KB |
subtask_1_06.txt | AC | 53 ms | 1408 KB |
subtask_1_07.txt | AC | 55 ms | 1408 KB |
subtask_1_08.txt | AC | 55 ms | 1408 KB |
subtask_1_09.txt | AC | 54 ms | 1408 KB |
subtask_1_10.txt | AC | 2 ms | 1024 KB |
subtask_1_11.txt | AC | 2 ms | 1024 KB |