Submission #1691486
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b) for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
const int N = 100000;
const int oo = 0x3f3f3f3f;
template<typename T> T read() {
T n(0), f(1);
char ch = getchar();
for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
for(; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48;
return n * f;
}
int n;
int a[N + 5], f[N + 5][2];
int main() {
#ifdef Wearry
freopen("data.txt", "r", stdin);
freopen("ans.txt", "w", stdout);
#endif
scanf("%d", &n);
f[1][0] = f[1][1] = 1;
for(int i = 1; i <= n; ++i) {
scanf("%d", a + i);
if(i > 1) {
f[i][1] = f[i][0] = min(f[i-1][0], f[i-1][1]) + 1;
if(a[i] >= a[i-1]) chkmin(f[i][1], f[i-1][1]);
if(a[i] <= a[i-1]) chkmin(f[i][0], f[i-1][0]);
}
}
printf("%d\n", min(f[n][0], f[n][1]));
return 0;
}
Submission Info
Submission Time
2017-10-18 10:12:56+0900
Task
A - Sorted Arrays
User
Wearry
Language
C++14 (GCC 5.4.1)
Score
300
Code Size
1313 Byte
Status
AC
Exec Time
13 ms
Memory
1408 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:36:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:40:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", a + i);
^
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
1 ms
256 KB
sample_02.txt
AC
1 ms
256 KB
sample_03.txt
AC
1 ms
256 KB
subtask_1_01.txt
AC
8 ms
896 KB
subtask_1_02.txt
AC
7 ms
768 KB
subtask_1_03.txt
AC
5 ms
640 KB
subtask_1_04.txt
AC
13 ms
1408 KB
subtask_1_05.txt
AC
13 ms
1408 KB
subtask_1_06.txt
AC
13 ms
1408 KB
subtask_1_07.txt
AC
13 ms
1408 KB
subtask_1_08.txt
AC
13 ms
1408 KB
subtask_1_09.txt
AC
13 ms
1408 KB
subtask_1_10.txt
AC
1 ms
256 KB
subtask_1_11.txt
AC
1 ms
256 KB