Submission #1221809


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	int n;
	int a[112345];
	
	cin >> n;
	REP(i, n) scanf("%d", a + i);
	
	int ans = 1;
	int f = -1;
	
	REP(i, n - 1) {
		if (f == -1) {
			if (a[i] == a[i + 1]) f = 2;
			else f = a[i] < a[i + 1];
		}
		
		if (a[i] > a[i + 1]) {
			if (f == 2) {
				f = 0;
			}
			if (f == 1) {
				f = -1;
				ans++;
			}
		}
		
		if (a[i] < a[i + 1]) {
			if (f == 2) {
				f = 1;
			}
			if (f == 0) {
				f = -1;
				ans++;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Submission Info

Submission Time
Task A - Sorted Arrays
User tkmst201
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1116 Byte
Status AC
Exec Time 13 ms
Memory 640 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:27:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  REP(i, n) scanf("%d", a + i);
                              ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 17
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 512 KB
subtask_1_02.txt AC 7 ms 384 KB
subtask_1_03.txt AC 5 ms 384 KB
subtask_1_04.txt AC 13 ms 640 KB
subtask_1_05.txt AC 13 ms 640 KB
subtask_1_06.txt AC 13 ms 640 KB
subtask_1_07.txt AC 13 ms 640 KB
subtask_1_08.txt AC 13 ms 640 KB
subtask_1_09.txt AC 13 ms 640 KB
subtask_1_10.txt AC 1 ms 256 KB
subtask_1_11.txt AC 1 ms 256 KB