Submission #226172

#TimeUsernameProblemLanguageResultExecution timeMemory
226172AaronNaiduRectangles (IOI19_rect)C++14
37 / 100
5078 ms40364 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m;
vector<pair<int, int> > topLeft;
vector<pair<int, int> > bottomRight;
vector<vector<int> > board; 

bool works(int startx, int endx, int starty, int endy) {
    if (startx > endx or starty > endy)
    {
        return false;
    }
    
    for (int x = startx; x <= endx; x++)
    {
        for (int y = starty; y <= endy; y++)
        {
            if (board[x][y] >= board[startx-1][y] or board[x][y] >= board[endx+1][y] or board[x][y] >= board[x][starty-1] or board[x][y] >= board[x][endy+1])
            {
                return false;
            }
            
        }       
    }
    //cout << startx << "," << starty << " to " << endx << "," << endy << "\n";
    return true;
}

ll count_rectangles(vector<vector<int> > a) {
    n = a.size();
    m = a[0].size();
    board = a;

    for (int i = 1; i < n - 1; i++)
    {
        for (int j = 1; j < m - 1; j++)
        {
            if (a[i][j] < a[i-1][j] and a[i][j] < a[i][j-1])
            {
                topLeft.push_back({i,j});
                //cout << "Top left could be " << i << "," << j << "\n";
            }
            if (a[i][j] < a[i+1][j] and a[i][j] < a[i][j+1])
            {
                bottomRight.push_back({i,j});
                //cout << "Bottom right could be " << i << "," << j << "\n";
            }
        }
    }
    ll totalCount = 0;
    for (auto i : topLeft)
    {
        for (auto j : bottomRight)
        {
            //cout << "Trying " << i.first << "," << i.second << " to " << j.first << "," << j.second << "\n";
            totalCount += works(i.first,j.first, i.second, j.second);      
        }
    }
    return totalCount;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...