답안 #155872

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
155872 2019-10-01T10:47:29 Z vanic Rectangles (IOI19_rect) C++14
컴파일 오류
0 ms 0 KB
#include "rect.h"
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <unordered_map>
#include <map>
#include <stack>
#include <set>
#include <array>
 
using namespace std;
 
typedef long long ll;
const int maxn=2503;
 
int n, m;
int l[maxn][maxn];
//vector < int > r[maxn][maxn], c[maxn][maxn];
unordered_map < int, int > r[maxn], c[maxn];
int rind[maxn][maxn], cind[maxn][maxn];
pair < int, int > red[maxn][maxn], stup[maxn][maxn];
int bio2[maxn][maxn], bio3[maxn][maxn];
//vector < array < int, 4 > > bio;
unordered_map < ll, bool > bio;
 
inline int hashiraj(int b, int c){
	return b*maxn+c;
}
 
inline ll hashah(ll a, ll b, ll c, ll d){
	return a*maxn*maxn*maxn+b*maxn*maxn+c*maxn+d;
}
 
void upd1(int x){
	stack < pair < int, int > > q;
	q.push(make_pair(1e8, -1));
	for(int i=0; i<m; i++){
		while(q.top().first<=l[x][i]){
			q.pop();
		}
		red[x][i].first=q.top().second+1;
		q.push(make_pair(l[x][i], i));
	}
	while(!q.empty()){
		q.pop();
	}
	q.push(make_pair(1e8, m));
	for(int i=m-1; i>-1; i--){
		while(q.top().first<=l[x][i]){
			q.pop();
		}
		red[x][i].second=q.top().second-1;
		if(bio2[red[x][i].first][red[x][i].second]!=x+1){
			bio2[red[x][i].first][red[x][i].second]=x+1;
			rind[red[x][i].first][red[x][i].second]++;
			r[red[x][i].first][hashiraj(red[x][i].second, x)]=rind[red[x][i].first][red[x][i].second];
		}
		q.push(make_pair(l[x][i], i));
	}
}
 
void upd2(int x){
	stack < pair < int, int > > q;
	q.push(make_pair(1e8, -1));
	for(int i=0; i<n; i++){
		while(q.top().first<=l[i][x]){
			q.pop();
		}
		stup[i][x].first=q.top().second+1;
		q.push(make_pair(l[i][x], i));
	}
	while(!q.empty()){
		q.pop();
	}
	q.push(make_pair(1e8, n));
	for(int i=n-1; i>-1; i--){
		while(q.top().first<=l[i][x]){
			q.pop();
		}
		stup[i][x].second=q.top().second-1;
		if(bio3[stup[i][x].first][stup[i][x].second]!=x+1){
			bio3[stup[i][x].first][stup[i][x].second]=x+1;
			cind[stup[i][x].first][stup[i][x].second]++;
			c[stup[i][x].first][hashiraj(stup[i][x].second, x)]=cind[stup[i][x].first][stup[i][x].second];
		}
		q.push(make_pair(l[i][x], i));
	}
}
 
bool provjeri(int x, int y){
	int r1, r2, c1, c2;
	r1=red[x][y].first;
	r2=red[x][y].second;
	c1=stup[x][y].first;
	c2=stup[x][y].second;
	if(r1==0 || c1==0 || r2==m-1 || c2==n-1){
		return 0;
	}
	if(r[r1][hashiraj(r2, c2)]!=0 && r[r1][hashiraj(r2, c1)]!=0
	&& c[c1][hashiraj(c2, r2)]!=0 && c[c1][hashiraj(c2, r1)]!=0
	&& r[r1][hashiraj(r2, c2)]-r[r1][hashiraj(r2, c1)]==c2-c1 && c[c1][hashiraj(c2, r2)]-c[c1][hashiraj(c2, r1)]==r2-r1){
		if(!bio[hashah(r1, r2, c1, c2)]){
			bio[hashah(r1, r2, c1, c2)]=1;
			return 1;
		}
	}
	return 0;
}
 
long long count_rectangles(vector < vector < int > > a){
	n=a.size();
	m=a[0].size();
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			l[i][j]=a[i][j];
		}
	}
	for(int i=0; i<n; i++){
		upd1(i);
	}
	for(int i=0; i<m; i++){
		upd2(i);
	}
	int br=0;
	for(int i=1; i<n-1; i++){
		for(int j=1; j<m-1; j++){
			br+=provjeri(i, j);
		}
	}
	return br;
}
 

int main(){
	scanf("%d%d", &n, &m);
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			scanf("%d", &l[i][j]);
		}
	}
	for(int i=0; i<n; i++){
		upd1(i);
	}
	for(int i=0; i<m; i++){
		upd2(i);
	}
	int br=0;
	for(int i=1; i<n-1; i++){
		for(int j=1; j<m-1; j++){
			br+=provjeri(i, j);
		}
	}
	printf("%d\n", br);
	return 0;
}

Compilation message

rect.cpp: In function 'int main()':
rect.cpp:136:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
rect.cpp:139:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &l[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
/tmp/ccNp7zwO.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccHogOzx.o:rect.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status