Submission #434328

# Submission time Handle Problem Language Result Execution time Memory
434328 2021-06-21T00:34:20 Z dqhungdl Hexagonal Territory (APIO21_hexagon) C++17
0 / 100
661 ms 467640 KB
#include "hexagon.h"

#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> ii;
const long long MOD=1e9+7,INC=1500;
int DD[3005][3005];
bool block[3005][3005],mark[3005][3005];

void move(int &curX,int &curY,int d) {
	if(d==1)
		curY++;
	else if(d==2)
		curX++,curY++;
	else if(d==3)
		curX++;
	else if(d==4)
		curY--;
	else if(d==5)
		curX--,curY--;
	else
		curX--;
}

long long mult(long long x,long long k) {
	if(k==0)
		return 1;
	long long tmp=mult(x,k/2);
	if(k%2==0)
		return tmp*tmp%MOD;
	return tmp*tmp%MOD*x%MOD;
}

void dfs(int u,int v) {
	mark[u][v]=true;
	for(int d=1;d<=6;d++) {
		int newU=u,newV=v;
		move(newU,newV,d);
		if(newU<0||newU>2*INC||newV<0||newV>2*INC||block[newU][newV]||mark[newU][newV])
			continue;
		dfs(newU,newV);
	}
}

int draw_territory(int N, int A, int B,
                   std::vector<int> D, std::vector<int> L) {
	if(N==3) {
		long long l=L[0];
		long long cnt=l*(l+1)%MOD;
		long long dist=(l*(l+1)%MOD*mult(2,MOD-2)%MOD
		              +l*(l+1)%MOD*(2*l+1)%MOD*mult(6,MOD-2)%MOD)%MOD;
		return (cnt*A+dist*B)%MOD;
	} else if(accumulate(L.begin(),L.end(),0)<=2000) {
		int curX=0,curY=0;
		block[curX+INC][curY+INC]=true;
		for(int i=0;i<N;i++)
			while(L[i]--) {
				move(curX,curY,D[i]);
				block[curX+INC][curY+INC]=true;
			}
		dfs(0,0);
		for(int i=0;i<=2*INC;i++)
			for(int j=0;j<=2*INC;j++)
				DD[i][j]=-1;
		DD[INC][INC]=0;
		queue<ii> Q;
		Q.push({INC,INC});
		while(!Q.empty()) {
			int u=Q.front().first,v=Q.front().second;
			Q.pop();
			for(int d=1;d<=6;d++) {
				int newU=u,newV=v;
				move(newU,newV,d);
				if(newU<0||newU>2*INC||newV<0||newV>2*INC||DD[newU][newV]!=-1||mark[newU][newV])
					continue;
				DD[newU][newV]=DD[u][v]+1;
				Q.push({newU,newV});
			}
		}
		long long cnt=0,dist=0;
		for(int i=0;i<=2*INC;i++)
			for(int j=0;j<=2*INC;j++)
				if(!mark[i][j]) {
					cnt++;
					dist=(dist+DD[i][j])%MOD;
				}
		return (cnt*A+dist*B)%MOD;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 661 ms 467360 KB Output is correct
2 Correct 606 ms 465536 KB Output is correct
3 Correct 577 ms 466736 KB Output is correct
4 Correct 579 ms 466628 KB Output is correct
5 Correct 602 ms 467012 KB Output is correct
6 Correct 592 ms 467456 KB Output is correct
7 Correct 636 ms 467100 KB Output is correct
8 Correct 584 ms 467552 KB Output is correct
9 Correct 595 ms 467280 KB Output is correct
10 Correct 587 ms 467284 KB Output is correct
11 Correct 588 ms 467140 KB Output is correct
12 Correct 589 ms 462620 KB Output is correct
13 Correct 617 ms 459708 KB Output is correct
14 Correct 589 ms 460720 KB Output is correct
15 Correct 611 ms 467168 KB Output is correct
16 Correct 609 ms 467448 KB Output is correct
17 Correct 581 ms 467268 KB Output is correct
18 Incorrect 1 ms 204 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 590 ms 467368 KB Output is correct
2 Correct 588 ms 465468 KB Output is correct
3 Correct 592 ms 466800 KB Output is correct
4 Correct 573 ms 466564 KB Output is correct
5 Correct 597 ms 467020 KB Output is correct
6 Correct 618 ms 467440 KB Output is correct
7 Correct 566 ms 467156 KB Output is correct
8 Correct 607 ms 467640 KB Output is correct
9 Correct 603 ms 467396 KB Output is correct
10 Correct 573 ms 467300 KB Output is correct
11 Correct 589 ms 467112 KB Output is correct
12 Correct 602 ms 462532 KB Output is correct
13 Correct 589 ms 459740 KB Output is correct
14 Correct 588 ms 460844 KB Output is correct
15 Correct 605 ms 467316 KB Output is correct
16 Correct 587 ms 467564 KB Output is correct
17 Correct 585 ms 467172 KB Output is correct
18 Incorrect 1 ms 204 KB Output isn't correct
19 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 583 ms 467280 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -