Submission #1231384


Source Code Expand

#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int main (){
    int n;
    scanf("%d", &n);
    vector<int> data;
    int result = 1;
    int flag = 0;
    int last;
    for (int i = 0; i < n; i++) {
        int temp;
        scanf("%d", &temp);
        if (i == 0) {
            last = temp;
        }
        else {
            if (temp > last) {
                if (flag == 0)
                    flag = 1;
                if (flag == -1) {
                    flag = 0;
                    result++;
                }
            }
            if (temp < last) {
                if (flag == 0)
                    flag = -1;
                if (flag == 1) {
                    result++;
                    flag = 0;
                }
            }
            last = temp;
        }
    }

        printf("%d", result);
    
}

Submission Info

Submission Time
Task A - Sorted Arrays
User indcn20170939
Language C++14 (GCC 5.4.1)
Score 300
Code Size 926 Byte
Status AC
Exec Time 12 ms
Memory 128 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:10:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:17:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &temp);
                           ^

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 128 KB
sample_02.txt AC 1 ms 128 KB
sample_03.txt AC 1 ms 128 KB
subtask_1_01.txt AC 7 ms 128 KB
subtask_1_02.txt AC 6 ms 128 KB
subtask_1_03.txt AC 4 ms 128 KB
subtask_1_04.txt AC 12 ms 128 KB
subtask_1_05.txt AC 12 ms 128 KB
subtask_1_06.txt AC 12 ms 128 KB
subtask_1_07.txt AC 12 ms 128 KB
subtask_1_08.txt AC 12 ms 128 KB
subtask_1_09.txt AC 12 ms 128 KB
subtask_1_10.txt AC 0 ms 128 KB
subtask_1_11.txt AC 1 ms 128 KB