Cod sursa(job #3291784)

Utilizator CosminaneBoac Mihai Cosmin Cosminane Data 5 aprilie 2025 16:51:39
Problema Ograzi Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <fstream>
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std;
struct elem{
	int x, y;
};
unordered_map <int, unordered_map <int, int>> f;
vector <elem> v;
int w, h;
int check(int x, int y, int poz){
	if( poz == 0 ){
		return 0;
	}
	poz--;
	//cout << x << ' ' << y << ' ' << v[poz].x << ' ' << v[poz].y << '\n';
	if( v[poz].x + w >= x && v[poz].y + h >= y ){
		return 1;
	}
	return 0;
}
int main(){
	int n, m, i, x, y, r, ad;
	ifstream fin( "ograzi.in" );
	ofstream fout( "ograzi.out" );
	fin >> n >> m >> w >> h;
	for( i = 0; i < n; i++ ){
		fin >> x >> y;
		v.push_back( { x, y } );
		f[x / w][y / h] = i + 1;
	}
	r = 0;
	for( i = 0; i < m; i++ ){
		fin >> x >> y;
		ad = max( check( x, y, f[x / w][y / h] ), check( x, y, f[x / w - 1][y / h] ) );
		ad = max( check( x, y, f[x / w][y / h - 1] ), ad );
		ad = max( check( x, y, f[x / w - 1][y / h - 1] ), ad );
		r += ad;
	}
	fout << r;
	return 0;
}