답안 #568665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568665 2022-05-26T03:02:59 Z amunduzbaev 육각형 영역 (APIO21_hexagon) C++17
20 / 100
1203 ms 1048576 KB
#include "hexagon.h"

#ifndef EVAL
#include "grader.cpp"
#endif

#include "bits/stdc++.h"
using namespace std;
#define ar array
const int mod = 1e9 + 7;
const int N = 2e3 + 5;
int is[N][N], used[N][N];

int bp(int a, int b){
	int r = 1;
	while(b){
		if(b & 1) r = r * 1ll * a % mod;
		b >>= 1, a = a * 1ll * a % mod;
	} return r;
}

int draw_territory(int n, int A, int B, vector<int> d, vector<int> l) {
	if(n == 3){
		int L = l[0];
		int res = (L + 1) * 1ll * (L + 2) / 2 % mod * A % mod;
		res = (res + L * 1ll * (L + 1) % mod * (2 * L + 1) % mod * bp(6, mod - 2) % mod * B % mod) % mod; 
		res = (res + L * 1ll * (L + 1) / 2 % mod * B % mod) % mod;
		return res;
	}
	
	//~ assert(false);
	int ch[6][3] = {
		{1, 1},
		{1, 0},
		{0, -1},
		{-1, -1},
		{-1, 0},
		{0, 1}
	};
	
	ar<int, 2> c {}; 
	vector<ar<int, 2>> p; p.push_back(c);
	int _X = 0, _Y = 0;
	for(int i=0;i<n;i++){ --d[i];
		for(int k=0;k<l[i];k++){
			for(int t=0;t<2;t++) c[t] += ch[d[i]][t];
			p.push_back(c);
			_X = min(_X, c[0]);
			_Y = min(_Y, c[1]);
		}
	}
	
	//~ cout<<_X<<" "<<_Y<<"\n";
	_X = 1 - _X, _Y = 1 - _Y;
	//~ cout<<"\n";
	int last = 1;
	for(auto& x : p){
		x[0] = x[0] + _X; 
		x[1] = x[1] + _Y; 
		is[x[0]][x[1]] = last++;
	} 
	
	queue<int> q;
	for(int i=0;i<N;i++){
		used[0][i] = used[i][0] = used[N - 1][i] = used[i][N - 1] = 1;
		q.push(i);
		q.push(N * (N - 1) + i);
		if(i && i + 1 < N){
			q.push(i * N);
			q.push(i * N + N - 1);
		}
	}
	
	auto check = [&](int x, int y) { return (0 <= x && x < N && 0 <= y && y < N); };
	
	while(!q.empty()){
		int u = q.front(); q.pop();
		int x = u / N, y = u % N;
		for(int t=0;t<6;t++){
			//~ if(ch[t][0] == ch[t][1]) continue;
			int tx = x + ch[t][0], ty = y + ch[t][1];
			if(check(tx, ty) && !is[tx][ty] && !used[tx][ty]){
				used[tx][ty] = 1;
				q.push(tx * N + ty);
			}
		}
	}
	
	//~ for(int i=0;i<15;i++){
		//~ for(int j=0;j<15;j++){
			//~ cout<<is[i][j]<<" ";
		//~ } cout<<"\n";
	//~ } cout<<"\n";
	
	//~ _X = 1 - _X;
	//~ _Y = 1 - _Y;
	memset(is, 0, sizeof is);
	q.push(_X * N + _Y);
	is[_X][_Y] = 1;
	while(!q.empty()){
		int u = q.front(); q.pop();
		int x = u / N, y = u % N;
		for(int t=0;t<6;t++){
			//~ if(ch[t][0] == ch[t][1]) continue;
			int tx = x + ch[t][0], ty = y + ch[t][1];
			if(check(tx, ty) && !is[tx][ty] && !used[tx][ty]){
				is[tx][ty] = is[x][y] + 1;
				q.push(tx * N + ty);
			}
		}
	}
	
	//~ for(int i=0;i<15;i++){
		//~ for(int j=0;j<15;j++){
			//~ cout<<is[i][j]<<" ";
		//~ } cout<<"\n";
	//~ } cout<<"\n";
	
	int res = 0;
	//~ vector<int> D(15);
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(!is[i][j]) continue;
			is[i][j]--;
			//~ D[is[i][j]]++;
			//~ cout<<is[i][j]<<" "<<i<<" "<<j<<"\n";
			res = (res + is[i][j] * 1ll * B + A) % mod;
		}
	}
	//~ for(int i=0;i<15;i++) cout<<i<<" "<<D[i]<<"\n";
	//~ cout<<"\n";
	return res;
}

/*

17 2 3
1 1
2 2
3 2
4 1
5 1
4 1
3 1
2 2
1 3
6 2
2 3
3 1
4 6
5 3
6 3
6 2
1 1

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 31720 KB Output is correct
2 Correct 126 ms 31684 KB Output is correct
3 Correct 157 ms 31804 KB Output is correct
4 Correct 122 ms 31764 KB Output is correct
5 Correct 122 ms 31692 KB Output is correct
6 Correct 122 ms 31728 KB Output is correct
7 Correct 126 ms 31712 KB Output is correct
8 Correct 125 ms 31732 KB Output is correct
9 Correct 138 ms 31736 KB Output is correct
10 Correct 130 ms 31808 KB Output is correct
11 Correct 128 ms 31780 KB Output is correct
12 Correct 153 ms 31772 KB Output is correct
13 Correct 146 ms 31692 KB Output is correct
14 Correct 131 ms 31768 KB Output is correct
15 Correct 132 ms 31788 KB Output is correct
16 Correct 119 ms 31764 KB Output is correct
17 Correct 127 ms 31716 KB Output is correct
18 Correct 1 ms 308 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 3652 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Runtime error 7 ms 3652 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 31748 KB Output is correct
2 Correct 130 ms 31688 KB Output is correct
3 Correct 130 ms 31748 KB Output is correct
4 Correct 122 ms 31784 KB Output is correct
5 Correct 137 ms 31708 KB Output is correct
6 Correct 165 ms 31720 KB Output is correct
7 Correct 134 ms 31808 KB Output is correct
8 Correct 116 ms 31744 KB Output is correct
9 Correct 121 ms 31692 KB Output is correct
10 Correct 136 ms 31716 KB Output is correct
11 Correct 120 ms 31732 KB Output is correct
12 Correct 142 ms 31912 KB Output is correct
13 Correct 130 ms 31692 KB Output is correct
14 Correct 123 ms 31692 KB Output is correct
15 Correct 119 ms 31812 KB Output is correct
16 Correct 143 ms 31768 KB Output is correct
17 Correct 192 ms 31724 KB Output is correct
18 Runtime error 6 ms 3652 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Runtime error 1203 ms 1048576 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 31772 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 175 ms 31692 KB Output is correct
7 Correct 123 ms 31780 KB Output is correct
8 Correct 144 ms 31692 KB Output is correct
9 Correct 126 ms 31808 KB Output is correct
10 Correct 138 ms 31692 KB Output is correct
11 Correct 141 ms 31704 KB Output is correct
12 Correct 145 ms 31772 KB Output is correct
13 Correct 121 ms 31764 KB Output is correct
14 Correct 123 ms 31852 KB Output is correct
15 Correct 120 ms 31692 KB Output is correct
16 Correct 137 ms 31792 KB Output is correct
17 Correct 120 ms 31704 KB Output is correct
18 Correct 139 ms 31892 KB Output is correct
19 Correct 120 ms 31792 KB Output is correct
20 Correct 123 ms 31712 KB Output is correct
21 Correct 121 ms 31720 KB Output is correct
22 Runtime error 6 ms 3712 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -