Submission #1868495


Source Code Expand

#include <stdio.h>
#include <bits/stdc++.h>			

#define pb push_back
#define pf push_front
#define pp pop_back
#define sz(a) (int)(a.size())
#define mp make_pair
#define F first
#define S second
#define next _next
#define prev _prev
#define left _left
#define right _right
#define y1 _y1
#define all(x) x.begin(), x.end()

using namespace std;

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

const int N = (int)1e6 + 123;
const ll INF = (ll)1e18 + 123;
const int inf = (int)1e9 + 123;
const int MOD = (int)1e9 + 7;

void megaRandom() {
	unsigned int FOR;
 	asm("rdtsc" : "=A"(FOR));
  srand(FOR);
}

int n, a[N];

int main() {
	megaRandom();
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) 
		scanf("%d", &a[i]);
	int last = -1, type = -1; // 0 decreasing, 1 increasing
	int cnt = 0;
	for(int i = 1; i <= n; i ++) {
		if(last == -1) {
			cnt ++;
			last = a[i];
		} else {
			if(type == -1) {
				if(last > a[i]) type = 0;
				if(last < a[i]) type = 1;
			} else {
				if(type == 0 && last < a[i]) {
					last = type = -1;
					i = i - 1;
					continue;
			 	}
			 	if(type == 1 && last > a[i]) {
			 		last = type = -1;
			 		i = i - 1;
			 		continue;
			 	}
			}
			last = a[i];
		}
	}
	printf("%d", cnt);
	return 0;         
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:43:21: 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
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 12 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