Submission #824720

#TimeUsernameProblemLanguageResultExecution timeMemory
824720tolbiRectangles (IOI19_rect)C++17
10 / 100
11 ms852 KiB
#pragma optimize("Bismillahirrahmanirrahim")
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█■█
//█─█─█▄─█▄─█─█─█─█
//Allahuekber
//ahmet23 orz...
//FatihSultanMehmedHan
//YavuzSultanSelimHan
//AbdulhamidHan
//Sani buyuk Osman Pasa Plevneden cikmam diyor
#define author tolbi
#include <bits/stdc++.h>
using namespace std;
template<typename X, typename Y> istream& operator>>(istream& is, pair<X,Y> &pr){return is>>pr.first>>pr.second;}
template<typename X, typename Y> ostream& operator<<(ostream& os, pair<X,Y> pr){return os<<pr.first<<" "<<pr.second;}
template<typename T> istream& operator>>(istream& is, vector<T> &arr){for (auto &it : arr) is>>it; return is;}
template<typename T> ostream& operator<<(ostream& os, vector<T> arr){for (auto &it : arr) os<<it<<" "; return os;}
template<typename T,size_t Y> istream& operator>>(istream& is, array<T,Y> &arr){for (auto &it : arr) is>>it; return is;}
template<typename T,size_t Y> ostream& operator<<(ostream& os, array<T,Y> arr){for (auto &it : arr) os<<it<<" "; return os;}
#define deci(x) int x;cin>>x;
#define decstr(x) string x;cin>>x;
#define cinarr(x) for (auto &it : x) cin>>it;
#define coutarr(x) for (auto &it :x) cout<<it<<" ";cout<<endl;
#define sortarr(x) sort(x.begin(), x.end())
#define sortrarr(x) sort(x.rbegin(), x.rend())
#define rev(x) reverse(x.begin(), x.end())
#define tol(bi) (1LL<<((int)(bi)))
typedef long long ll;
const int MOD = 1e9+7;
mt19937 ayahya(chrono::high_resolution_clock().now().time_since_epoch().count());
#include "rect.h"
ll subtask6(vector<vector<int>> &arr){
	int n = arr.size();
	int m = arr[0].size();
	vector<vector<bool>> vis(n,vector<bool>(m,false));
	ll ans = 0;
	function<void(int,int)> dfs;
	dfs = [&](int x, int y){
		if (x<0 || x>=n || y<0 || y>=m) return;
		if (arr[x][y]==1) return;
		if (vis[x][y]) return;
		vis[x][y]=true;
		dfs(x-1,y);
		dfs(x+1,y);
		dfs(x,y-1);
		dfs(x,y+1);
	};
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if (arr[i][j]==1) continue;
			if (vis[i][j]) continue;
			int rx=i,ry=j;
			for (;rx<n&&!arr[rx][j];rx++);rx--;
			for (;ry<m&&!arr[i][ry];ry++);ry--;
			dfs(i,j);
			if (i==0 || i==n-1) continue;
			if (j==0 || j==m-1) continue;
			if (rx==0 || rx==n-1) continue;
			if (ry==0 || ry==m-1) continue;
			bool boolean=true;
			for (int x = i; x <= rx; x++){
				for (int y = j; y <= ry; y++){
					if (arr[x][y]>=arr[i-1][y] || arr[x][y]>=arr[rx+1][y]) {
						boolean=false;
						break;
					}
					if (arr[x][y]>=arr[x][j-1] || arr[x][y]>=arr[i][ry+1]){
						boolean=false;
						break;
					}
				}
				if (!boolean) break;
			}
			ans+=boolean;
		}
	}
	return ans;
}
long long count_rectangles(vector<vector<int> > a) {
	int n = a.size();
	int m = a[0].size();
	bool boolean=true;
	for (int i = 0; i < a.size(); i++){
		for (int j = 0; j < a[i].size(); j++){
			if (a[i][j]>1) {
				boolean=false;
				break;
			}
		}
		if (!boolean) break;
	}
	if (boolean) return subtask6(a);
	auto check = [&](int lx, int rx, int ly, int ry)->bool{
		for (int i = lx; i <= rx; i++){
			for (int j = ly; j <= ry; j++){
				if (a[i][j]>=a[i][ly-1] || a[i][j]>=a[i][ry+1]) return false;
				if (a[i][j]>=a[lx-1][j] || a[i][j]>=a[rx+1][j]) return false;
			}
		}
		return true;
	};
	ll ans = 0;
	for (int i = 1; i < n-1; i++){
		for (int j = i; j < n-1; j++){
			for (int k = 1; k < m-1; k++){
				for (int z = k; z < m-1; z++){
					if (check(i,j,k,z)) ans++;
				}
			}
		}
	}
	return ans;
}

Compilation message (stderr)

rect.cpp:1: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    1 | #pragma optimize("Bismillahirrahmanirrahim")
      | 
rect.cpp: In function 'll subtask6(std::vector<std::vector<int> >&)':
rect.cpp:53:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   53 |    for (;rx<n&&!arr[rx][j];rx++);rx--;
      |    ^~~
rect.cpp:53:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   53 |    for (;rx<n&&!arr[rx][j];rx++);rx--;
      |                                  ^~
rect.cpp:54:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   54 |    for (;ry<m&&!arr[i][ry];ry++);ry--;
      |    ^~~
rect.cpp:54:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   54 |    for (;ry<m&&!arr[i][ry];ry++);ry--;
      |                                  ^~
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:83:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |  for (int i = 0; i < a.size(); i++){
      |                  ~~^~~~~~~~~~
rect.cpp:84:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for (int j = 0; j < a[i].size(); j++){
      |                   ~~^~~~~~~~~~~~~
#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...