Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
6.1 kB
5
Indexable
Never
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <stdio.h>

#define CMD_INIT 1
#define CMD_NUMBER_OF_CANDIDATE 2
#define CMD_MAX_AREA 3

extern void init(int N, int mMap[20][20]);
extern int numberOfCandidate(int M, int mStructure[5]);
extern int maxArea(int M, int mStructure[5], int mSeaLevel);

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////

static int mMap[20][20];
static int mStructure[5];

static bool run()
{
	int numQuery;
	int N, M, mSeaLevel;
	int userAns, ans;

	bool isCorrect = false;

	scanf("%d", &numQuery);

	for (int i = 0; i < numQuery; ++i)
	{
		int cmd;
		scanf("%d", &cmd);

		switch (cmd)
		{
		case CMD_INIT:
			scanf("%d", &N);
			for (int j = 0; j < N; j++)
				for (int k = 0; k < N; k++)
					scanf("%d", &mMap[j][k]);
			init(N, mMap);
			isCorrect = true;
			break;
		case CMD_NUMBER_OF_CANDIDATE:
			scanf("%d", &M);
			for (int j = 0; j < M; j++)
				scanf("%d", &mStructure[j]);
			userAns = numberOfCandidate(M, mStructure);
			scanf("%d", &ans);
			if (userAns != ans)
			{
				isCorrect = false;
			}
			break;
		case CMD_MAX_AREA:
			scanf("%d", &M);
			for (int j = 0; j < M; j++)
				scanf("%d", &mStructure[j]);
			scanf("%d", &mSeaLevel);
			userAns = maxArea(M, mStructure, mSeaLevel);
			scanf("%d", &ans);
			if (userAns != ans)
			{
				isCorrect = false;
			}
			break;
		default:
			isCorrect = false;
			break;
		}
	}
	return isCorrect;
}

int main()
{
	setbuf(stdout, NULL);
	// freopen("sample_input.txt", "r", stdin);

	int T, MARK;
	scanf("%d %d", &T, &MARK);

	for (int tc = 1; tc <= T; tc++)
	{
		int score = run() ? MARK : 0;
		printf("#%d %d\n", tc, score);
	}

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int map[22][22], n;

int h[4][2]={
	{-1, 0},
	{0, 1},
	{1, 0},
	{0, -1}
};
struct Point{
	int x;
	int y;
	Point(){}
	Point(int xx, int yy){
		x=xx;
		y=yy;
	}
} q[600];

int visit[22][22];
int cuoi;

void init(int N, int mMap[20][20])
{
	n=N;
	
	for(int i=0;i<N;i++) for(int j=0;j<N;j++) map[i+1][j+1]=mMap[i][j];
	
}

int numberOfCandidate(int M, int mStructure[5])
{
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			
			int k1, k2;
			int ref=mStructure[0]+map[i][j];
			int refRv=mStructure[M-1]+map[i][j];
			if(j+M <= n+1){
				for(k1=0;k1<M;k1++)
				{		
					int c=map[i][j+k1]+mStructure[k1];
					if(c!=ref) break;
				}

				for(k2=0;k2<M;k2++)
				{		
					int c=map[i][j+k2]+mStructure[M-1-k2];
					if(c!=refRv) break;	
				}

				if(k1==M || k2==M) {
					ans++;
				}
			}
			if(M==1) continue;

			if(i+M <=n+1){
				for(k1=0;k1<M;k1++)
				{		
					int c=map[i+k1][j]+mStructure[k1];
					if(c!=ref) break;	
				
				}
				
				for(k2=0;k2<M;k2++)
				{		
					int c=map[i+k2][j]+mStructure[M-1-k2];
					if(c!=refRv) break;	
				
				}
				if(k1==M || k2==M) {
					ans++;
				}
			}

		}
	}
	/*if(ans==0) return -1;*/
	return ans;
}

int calMax(int mSeaLevel){
	for(int i=0;i<22;i++){
		for(int j=0;j<22;j++){
			visit[i][j]=0;	
		}
	}
	cuoi=-1;
	for(int j=0;j<n+2;j++){
			visit[0][j]=1;
			q[++cuoi]=Point(0,j);	
	}
	for(int j=0;j<n+2;j++){
			visit[j][n+1]=1;
			q[++cuoi]=Point(j,n+1);
	}		
	for(int j=0;j<n+2;j++){
			visit[n+1][j]=1;
			q[++cuoi]=Point(n+1,j);	
	}
	for(int j=0;j<n+2;j++){
			visit[j][0]=1;
			q[++cuoi]=Point(j,0);
	}
	int ans=n*n;
	int dau=-1;
	while(dau<cuoi+1){
		dau++;
		Point t=q[dau];
		for(int i=0;i<4;i++){
			Point t1;
			t1.x=t.x+h[i][0];
			t1.y=t.y+h[i][1];
			if(t1.x < 1 || t1.x > n || t1.y < 1 || t1.y > n) continue;
			if(visit[t1.x][t1.y]==1) continue;
			if(map[t1.x][t1.y]>=mSeaLevel) continue;
			visit[t1.x][t1.y]=1;
			ans--;
			cuoi++;
			q[cuoi]=t1;
		}
	}
	return ans;
}



int maxArea(int M, int mStructure[5], int mSeaLevel)
{
	bool check=false;
	int max=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			int k1, k2;
			int ref=mStructure[0]+map[i][j];
			int refRv=mStructure[M-1]+map[i][j];
			if(j+M <= n){
				for(k1=0;k1<M;k1++)
				{		
					int c=map[i][j+k1]+mStructure[k1];
					if(c!=ref)
					{
						break;	
					}
				
				}
				if(k1==M){
					check=true;
					for(int k1=0;k1<M;k1++) map[i][j+k1]+=mStructure[k1];
					int t=calMax(mSeaLevel);
					for(int k1=0;k1<M;k1++) map[i][j+k1]-=mStructure[k1];
					if(max<t) max=t;
				}

				for(k2=0;k2<M;k2++)
				{		
					int c=map[i][j+k2]+mStructure[M-k2-1];
					if(c!=refRv)
					{
						break;	
					}
				
				
				}
				if(k2==M){
					check=true;
					for(int k2=0;k2<M;k2++) map[i][j+k2]+=mStructure[M-k2-1];
					int t=calMax(mSeaLevel);
					for(int k2=0;k2<M;k2++) map[i][j+k2]-=mStructure[M-k2-1];
					if(max<t) max=t;
				}
			}
			
			if(M==1) continue;
			if(i+M<=n){
				for(k1=0;k1<M;k1++)
				{		
					int c=map[i+k1][j]+mStructure[k1];
					if(c!=ref)
					{
						break;	
					}
				}
				if(k1==M){
					check=true;
					for(int k1=0;k1<M;k1++) map[i+k1][j]+=mStructure[k1];
					int t=calMax(mSeaLevel);
					for(int k1=0;k1<M;k1++) map[i+k1][j]-=mStructure[k1];
					if(max<t) max=t;
				}
				
				for(k2=0;k2<M;k2++)
				{		
					int c=map[i+k2][j]+mStructure[M-k2-1];
					if(c!=refRv)
					{
						break;	
					}
				}
				if(k2==M){
					check=true;
					for(int k2=0;k2<M;k2++) map[i+k2][j]+=mStructure[M-k2-1];
					int t=calMax(mSeaLevel);
					for(int k2=0;k2<M;k2++) map[i+k2][j]-=mStructure[M-k2-1];
					if(max<t) max=t;
				}
			}
			
		}
	}
	if(!check) return -1;
	return max;
}




25 100
12
1 6 1 2 1 5 5 5 3 1 3 1 1 5 1 4 5 5 5 5 2 1 1 1 4 5 1 4 5 5 5 5 3 2 3 4 1 2
2 3 4 3 4 2
2 1 4 36
3 5 1 5 1 3 5 4 23
2 3 1 1 1 9
3 3 5 2 3 6 3
3 2 1 4 5 18
3 5 5 5 4 5 5 5 -1
2 2 5 2 8
2 5 2 5 5 5 4 1
2 5 1 2 1 2 1 0
3 2 1 4 10 0