635A - Orchestra - CodeForces Solution


brute force implementation *1100

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <cmath>
#include <stack> 
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;
int arr[11][11];

int sum(int i,int j ,int a,int b){
	int ss=0;
	for(int k=i;k<i+a;k++ ){
		for(int u=j;u<j+b;u++)ss+=arr[k][u];
	}
	return ss;
}
int main(){
int n,m;
cin>>n>>m;
int nn,k;
cin>>nn>>k;
for(int i=0;i<nn;i++){
int x,y;
cin>>x>>y;
	arr[x-1][y-1]=1;
}
int ans[n][m];
for(int i=0;i<n;i++){
	for(int j=0;j<m;j++){
		if(i==0&&j==0)ans[i][j]=arr[i][j];
		else if(i==0)ans[i][j]=arr[i][j]+ans[i][j-1];
		else if(j==0)ans[i][j]=arr[i][j]+ans[i-1][j];
		else{
			ans[i][j]=arr[i][j]+ans[i][j-1]+ans[i-1][j]-ans[i-1][j-1];
		}
	}
}

///////////////////////////
int sum=0;
for(int a=0;a<n;a++){
	for(int b=0;b<m;b++){
		for(int i=0;i<n-a;i++){
			for(int j=0;j<m-b;j++){
				int x;
			if(i==0&&j==0)x=ans[i+a][j+b];
			else if(i==0)x=ans[i+a][j+b]-ans[i+a][j-1];
			else if(j==0)x=ans[i+a][j+b]-ans[i-1][j+b];
			else x=x=ans[i+a][j+b]-ans[i-1][j+b]-ans[i+a][j-1]+ans[i-1][j-1];
			if(x>=k)sum++;
		//	cout<<a<<" "<<b<<" "<<x<<"\n";
			}
		}
	}
}cout<<sum<<"\n";
	return 0;
}


Comments

Submit
0 Comments
More Questions

979A - Pizza Pizza Pizza
731A - Night at the Museum
742A - Arpa’s hard exam and Mehrdad’s naive cheat
1492A - Three swimmers
1360E - Polygon
1517D - Explorer Space
1230B - Ania and Minimizing
1201A - Important Exam
676A - Nicholas and Permutation
431A - Black Square
474B - Worms
987B - High School Become Human
1223A - CME
1658B - Marin and Anti-coprime Permutation
14B - Young Photographer
143A - Help Vasilisa the Wise 2
320A - Magic Numbers
1658A - Marin and Photoshoot
514A - Chewbaсca and Number
382A - Ksenia and Pan Scales
734B - Anton and Digits
1080A - Petya and Origami
1642D - Repetitions Decoding
1440A - Buy the String
1658F - Juju and Binary String
478A - Initial Bet
981A - Antipalindrome
365A - Good Number
1204B - Mislove Has Lost an Array
1409D - Decrease the Sum of Digits