200A - Cinema - CodeForces Solution


brute force data structures *2400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define r(i,a,n) for (int i=a;i<n;i++)
int n,m,k,x,y,a,b,d[2010][2010],v[2010][2010];
bool solve(int x,int y,int k) {
	int l=max(1,x-k),r=min(x+k,n),t;
	r(i,l,r+1) {
		t=k-abs(i-x);
		if (y-t>0&&!v[i][y-t]) return a=i,b=y-t,1;
		if (y+t<=m&&!v[i][y+t]) return a=i,b=y+t,1;
	}
	return 0;
}
int main() {
	scanf("%d%d%d",&n,&m,&k);
	r(t,0,k) {
		scanf("%d%d",&x,&y);
		r(i,-2,3) r(j,-2,3) {
			if (x+i<1||x+i>n||y+j<1||y+j>m) continue;
			d[x][y]=max(d[x][y],d[x+i][y+j]-abs(i)-abs(j));
		}
		while (!solve(x,y,d[x][y]))d[x][y]++;
		printf("%d %d\n",a,b);
		v[a][b]=1;
	}
}/*1697935941.580456*/


Comments

Submit
0 Comments
More Questions

964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline
510A - Fox And Snake
1520B - Ordinary Numbers
1624A - Plus One on the Subset
350A - TL
1487A - Arena
1520D - Same Differences
376A - Lever
1305A - Kuroni and the Gifts
1609A - Divide and Multiply
149B - Martian Clock
205A - Little Elephant and Rozdil
1609B - William the Vigilant
978B - File Name
1426B - Symmetric Matrix
732B - Cormen --- The Best Friend Of a Man
1369A - FashionabLee
1474B - Different Divisors
1632B - Roof Construction
388A - Fox and Box Accumulation
451A - Game With Sticks
768A - Oath of the Night's Watch