Submission #1221358
Source Code Expand
#include <bits/stdc++.h>
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
struct S002 {
int n;
S002& operator > (long& x) {
n = x;
return *this;
}
S002& operator > (long&& x) {
n = x;
return *this;
}
S002& operator >= (long& x) {
if( scanf("%ld", &x) <= 0 ) exit(0);
return *this;
}
S002& operator >= (double& x) {
if( scanf("%lf", &x) <= 0 ) exit(0);
return *this;
}
S002& operator >= (std::string& s) {
if( not (std::cin >> s) ) exit(0);
return *this;
}
template<typename a>
S002& operator >= (std::vector<a>& v) {
v.resize(n);
for(long i = 0; i < n; ++i) {
*this >= v[i];
}
return *this;
}
template<typename a, std::size_t s>
S002& operator >= (std::array<a, s>& x) {
for(long i = 0; i < (long)s; ++i) {
*this >= x[i];
}
return *this;
}
};
struct Solver {
long n;
std::vector<long> xs;
Solver() {
S002 reader;
reader >= n >n>= xs;
}
long f(long begin) {
dumpl(begin);
if( n - begin <= 2 ) {
return 1;
}
long state;
if( xs[begin] == xs[begin+1] ) state = 0;
if( xs[begin] < xs[begin+1] ) state = 1;
if( xs[begin] > xs[begin+1] ) state = -1;
for(long i = begin+2; i < n; ++i) {
if( xs[i-1] < xs[i] ) {
if( state == -1 ) {
return 1 + f(i);
}
state = 1;
}
if( xs[i-1] > xs[i] ) {
if( state == 1 ) {
return 1 + f(i);
// res += 1;
}
state = -1;
}
}
return 1;
}
void solve() {
long res = f(0);
// if( n <= 2 ) {
// printf("1\n");
// return;
// }
// long state;
// if( xs[0] == xs[1] ) state = 0;
// if( xs[0] < xs[1] ) state = 1;
// if( xs[0] > xs[1] ) state = -1;
// long res = 1;
// for(long i = 2; i < n; ++i) {
// if( xs[i-1] < xs[i] ) {
// if( state == -1 ) {
// res += 1;
// }
// state = 1;
// }
// if( xs[i-1] > xs[i] ) {
// if( state == 1 ) {
// res += 1;
// }
// state = -1;
// }
// }
printf("%ld\n", res);
}
~Solver() { fprintf(stderr, "--end--\n"); }
};
int main() {
loop std::unique_ptr<Solver>(new Solver())->solve();
return 0;
}
Submission Info
Submission Time |
|
Task |
A - Sorted Arrays |
User |
spica314 |
Language |
C++14 (GCC 5.4.1) |
Score |
300 |
Code Size |
3056 Byte |
Status |
AC |
Exec Time |
13 ms |
Memory |
1024 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 |
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 |
768 KB |
subtask_1_02.txt |
AC |
6 ms |
640 KB |
subtask_1_03.txt |
AC |
5 ms |
512 KB |
subtask_1_04.txt |
AC |
13 ms |
1024 KB |
subtask_1_05.txt |
AC |
13 ms |
1024 KB |
subtask_1_06.txt |
AC |
13 ms |
1024 KB |
subtask_1_07.txt |
AC |
13 ms |
1024 KB |
subtask_1_08.txt |
AC |
12 ms |
1024 KB |
subtask_1_09.txt |
AC |
13 ms |
1024 KB |
subtask_1_10.txt |
AC |
1 ms |
256 KB |
subtask_1_11.txt |
AC |
1 ms |
256 KB |