Submission #1267538

#TimeUsernameProblemLanguageResultExecution timeMemory
1267538ti24dung_ntQuality Of Living (IOI10_quality)C++20
Compilation error
0 ms0 KiB
#include "grader.h"
#include "quality.h"

int rectangle(int row, int col, int hig, int wid, int q[3002][3002])
{
    int l = 1e10, r = -1e10;
    for(int i = 0; i < row; ++i)
    {
        for(int j = 0; j < col; ++j)
        {
            l = min(l, q[i][j]); r = max(r, q[i][j]);
        }
    }

    int a[3002][3002], sum[3002][3002], ans;
    while(l <= r)
    {
        int mid = (l + r) / 2;

        for(int i = 1; i <= row; ++i)
        {
            for(int j = 1; j <= col; ++j)
            {
                if(q[i - 1][j - 1] <= mid) a[i][j] = 1;
                else a[i][j] = -1;
            }
        }

        sum[0][0] = 0;
        for(int i = 1; i <= row; ++i) sum[i][0] = 0;
        for(int j = 1; j <= col; ++j) s[0][j] = 0;

        for(int i = 1; i <= row; ++i)
        {
            for(int j = 1; j <= col; ++j)
            {
                sum[i][j] = sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + a[i][j];
            }
        }

        bool check = false;
        for(int x1 = 1; x1 <= row - hig + 1; ++x1)
        {
            for(int y1 = 1; y1 <= col - wid + 1; ++y1)
            {
                int x2 = x1 + hig - 1, y2 = y1 + wid - 1;
                res = sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
                if(res > 0) check = true;
                if(check) break;
            }
            if(check) break;
        }

        if(check)
        {
            r = mid - 1;
            ans = mid;
        }
        else l = mid + 1;
    }

    return ans;

}

Compilation message (stderr)

quality.cpp: In function 'int rectangle(int, int, int, int, int (*)[3002])':
quality.cpp:6:13: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+10' to '2147483647' [-Woverflow]
    6 |     int l = 1e10, r = -1e10;
      |             ^~~~
quality.cpp:6:23: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+10' to '-2147483648' [-Woverflow]
    6 |     int l = 1e10, r = -1e10;
      |                       ^~~~~
quality.cpp:11:17: error: 'min' was not declared in this scope
   11 |             l = min(l, q[i][j]); r = max(r, q[i][j]);
      |                 ^~~
quality.cpp:11:38: error: 'max' was not declared in this scope
   11 |             l = min(l, q[i][j]); r = max(r, q[i][j]);
      |                                      ^~~
quality.cpp:31:39: error: 's' was not declared in this scope
   31 |         for(int j = 1; j <= col; ++j) s[0][j] = 0;
      |                                       ^
quality.cpp:47:17: error: 'res' was not declared in this scope
   47 |                 res = sum[x2][y2] - sum[x1 - 1][y2] - sum[x2][y1 - 1] + sum[x1 - 1][y1 - 1];
      |                 ^~~