Submission #1222172


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <vector>

#define NMAX (100000 + 7)

using namespace std;
int n, a[NMAX], ct = 1, val, last;

int main()
{
    //freopen(in, "r", stdin);
    //freopen(out, "w", stdout);
    scanf("%d", &n);
    if(n <= 2)
    {
        printf("1\n");
        return 0;
    }
    for(int i = 1; i<= n; ++i) scanf("%d", &a[i]);
    if(a[1] <= a[2]) val = 1;
    else val = 2;
    for(int i = 2; i<= n; ++i)
    {
        if(a[i] == a[i+1]) continue;
        if(val == 1)
        {
            //printf("check %d %d\n", a[i], last);
            if(a[i] >= last) {last = a[i];continue;}
            ++ct;
            //printf("check 1 %d\n", i);
            if(i <= n-1)
            {
                if(a[i] < a[i+1]) val = 1;
                else val = 2;
            }
            last = a[i];
            continue;
        }
        if(val == 2)
        {
            if(a[i] <= last) {last = a[i];continue;}
            ++ct;
            //printf("check 2 %d\n", i);
            if(i <= n-1)
            {
                if(a[i] < a[i+1]) val = 1;
                else val = 2;
            }
            last = a[i];
            continue;
        }
    }
    ++ct;
    if((a[n-2] <= a[n-1] && a[n-1] <= a[n]) || (a[n-2] >= a[n-1] && a[n-1] >= a[n])) -- ct;
    printf("%d\n", ct);
    return 0;
}

Submission Info

Submission Time
Task A - Sorted Arrays
User fluture
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1388 Byte
Status WA
Exec Time 12 ms
Memory 512 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:14:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:20:50: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i<= n; ++i) scanf("%d", &a[i]);
                                                  ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 2
WA × 1
AC × 10
WA × 7
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 128 KB
sample_02.txt WA 1 ms 128 KB
sample_03.txt AC 1 ms 128 KB
subtask_1_01.txt WA 8 ms 384 KB
subtask_1_02.txt AC 6 ms 384 KB
subtask_1_03.txt WA 4 ms 256 KB
subtask_1_04.txt WA 12 ms 512 KB
subtask_1_05.txt WA 12 ms 512 KB
subtask_1_06.txt AC 12 ms 512 KB
subtask_1_07.txt WA 12 ms 512 KB
subtask_1_08.txt AC 12 ms 512 KB
subtask_1_09.txt AC 12 ms 512 KB
subtask_1_10.txt AC 1 ms 128 KB
subtask_1_11.txt AC 1 ms 128 KB