CSES - Datatähti 2021 alku - Results
Submission details
Task:Alitaulukot
Sender:shmoul
Submission time:2020-10-05 22:35:03 +0300
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:23:13: warning: unused variable 'current' [-Wunused-variable]
         int current = nums[i];
             ^~~~~~~
input/code.cpp: In function 'void maxmin(int, int)':
input/code.cpp:41:16: error: 'INT_MIN' was not declared in this scope
     int tmax = INT_MIN;
                ^~~~~~~
input/code.cpp:41:16: note: suggested alternative: 'INT8_MIN'
     int tmax = INT_MIN;
                ^~~~~~~
                INT8_MIN
input/code.cpp:42:16: error: 'INT_MAX' was not declared in this scope
     int tmin = INT_MAX;
                ^~~~~~~
input/code.cpp:42:16: note: suggested alternative: 'INT8_MAX'
     int tmin = INT_MAX;
                ^~~~~~~
                INT8_MAX

Code

#include <iostream>
#include <string>
#include <algorithm>
int length;
int maxIndex;
int minIndex;
int max;
int min;
int* nums;
void maxmin(int start, int end); 
int main()
{
    int diff;
    std::cin >> length >> diff;
    nums = new int[length];
    int tablecount = length;
    for (int i = 0; i < length; i++)
    {
        std::cin >> nums[i];
    }
    for (int i = 0; i < length; i++)
    {
        int current = nums[i];
        for (int j = length-1; j > i; j--)
        {
            maxmin(i,j);
            int m1 = std::max(minIndex, maxIndex);
            if (max - min > diff)
            {
                j = m1;
                continue;
            }
            tablecount += j - i;
            j = m1;
        }
    }
    std::cout << tablecount;
}
void maxmin(int start, int end)
{
    int tmax = INT_MIN;
    int tmin = INT_MAX;
    int maxi = start;
    int mini = end;
    for (int i = start; i < end; i++)
    {
        if (nums[i] > tmax)
        {
            tmax = nums[i];
            maxi = i;
        }
        if (nums[i] < tmin)
        {
            tmin = nums[i];
            mini = i;
        }
    }
    max = tmax;
    min = tmin;
    maxIndex = maxi;
    minIndex = mini;
}