QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#228784#7637. Exactly Three Neighborsucup-team1209#AC ✓1ms3536kbC++203.6kb2023-10-28 14:12:592023-10-28 14:12:59

Judging History

你现在查看的是最新测评结果

  • [2023-10-28 14:12:59]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3536kb
  • [2023-10-28 14:12:59]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin, std::cout;
int n, m;
using u64 = unsigned long long;
using u128 = __int128_t;

using cp = std::complex<int>;

cp calc( std::vector<std::vector<int>> a) {
	int n = a.size();
	int m = a[0].size();
	int cnt = 0;
	for(int i = 0;i < n;++i) {
		for(int j = 0;j < m;++j) if(a[i][j] == 0) {
			cnt += 1;
			int sum = 0;
			for(int x : {1, n - 1})
				sum += a[(i + x) % n][j];
			for(int y : {1, m - 1})
				sum += a[i][(j + y) % m];
			if(sum != 1) {
				std::cerr << "error " << i << ' ' << j << '\n';
				assert(sum == 1);
			}
		}
	}
	n *= m;
	int gcd = std::__gcd(n, cnt);
	return cp(cnt / gcd, n / gcd);
}
std::vector<std::vector<int>> get(int p, int q) {
	if(p == q) return {};
	if(p == 0) return {{1}};
	if(p * 5 > q * 4) return {};
	if(p * 3 <= q * 2) {
		q *= 2;
		std::vector<std::vector<int>> ans(q, {1});
		for(int i = 0;i < p;++i) {
			ans[i * 3 + 0][0] = 0;
			ans[i * 3 + 1][0] = 0;
		}
		return ans;
	}
	if(p == 4 && q == 5) {
		std::vector<std::vector<int>> ans(5, std::vector<int>(5));
		ans[0][2] = ans[1][0] = ans[2][3] = ans[3][1] = ans[4][4] = 1;
		return ans;
	}
	if(p == 3 && q == 4) {
		std::vector<std::vector<int>> ans(8, std::vector<int>(8));
		ans[0][1] = ans[0][2] = 1;
		ans[1][5] = ans[1][6] = 1;
		ans[2][0] = ans[2][3] = 1;
		ans[3][0] = ans[3][3] = 1;
		ans[4][5] = ans[4][6] = 1;
		ans[5][1] = ans[5][2] = 1;
		ans[6][4] = ans[6][7] = 1;
		ans[7][4] = ans[7][7] = 1;
		return ans;
	}
	if(p == 7 && q == 10) {
		int n = 20, m = 20;
		std::vector<std::vector<int>> ans(n, std::vector<int>(m));
		for(auto a : {cp(0, 0), cp(0, 1), cp(0, 2), cp(0, 3), cp(0, 4), cp(0, 5)}) {
			for(int b = 0;b < 20;++b)
				for(int c = 0;c < 20;++c) {
					cp r = a + b * cp(2, 6) + c * cp(n - 1, 7);
					int x = r.real() % n;
					int y = r.imag() % m;
					ans[x][y] = 1;
				}
		}
		return ans;
	}
	if(p == 5 && q == 7) {
		int n = 14, m = 14;
		std::vector<std::vector<int>> ans(n, std::vector<int>(m));
		for(auto a : {cp(0, 0), cp(0, 1), cp(0, 2), cp(0, 3)}) {
			for(int b = 0;b < 20;++b)
				for(int c = 0;c < 20;++c) {
					cp r = a + b * cp(2, 4) + c * cp(n - 1, 5);
					int x = r.real() % n;
					int y = r.imag() % m;
					ans[x][y] = 1;
				}
		}
		return ans;
	}
	if(p == 7 && q == 9) {
		int n = 18, m = 6;
		std::vector<std::vector<int>> ans(n, std::vector<int>(m));
		for(auto a : {cp(0, 0), cp(0, 1)}) {
			for(int b = 0;b < 20;++b)
				for(int c = 0;c < 20;++c) {
					cp r = a + b * cp(n-3,5) + c * cp(3, 1);
					int x = r.real() % n;
					int y = r.imag() % m;
					ans[x][y] = 1;
				}
		}
		for(auto a : {cp(2, m-1), cp(n-2, 2)}) {
			for(int b = 0;b < 20;++b)
				for(int c = 0;c < 20;++c) {
					cp r = a + b * cp(3, 1) + c * cp(n-3,5);
					int x = r.real() % n;
					int y = r.imag() % m;
					ans[x][y] = 1;
				}
		}
		return ans;
	}
				//std::cerr << p << ' ' << q << '\n';

	assert(0);
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	/*
	for(int p = 0;p <= 10;++p) {
		for(int q = p;q <= 10;++q) if(p && q) {
			int gcd = std::__gcd(p, q);
			auto res = get(p / gcd, q / gcd);
			if(res.empty()) continue;
			if(calc(res) != cp(p / gcd, q / gcd)) {
				std::cerr << p << ' ' << q << '\n';
			}
		}
	}
	return 0;
	*/
	int p, q;
	cin >> p >> q;
	auto res = get(p, q);
	if(res.empty()) {
		cout << -1 << ' ' << -1 << '\n';
	} else {
		cout << res.size() << ' ' << res[0].size() << '\n';
		for(auto x : res) {
			for(auto y : x) cout.put("#."[y]);
			cout.put(10);
		}
		cout << std::flush;
//		cout << "res : " << calc(res) << '\n';
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3460kb

input:

2 3

output:

6 1
#
#
.
#
#
.

result:

ok good solution

Test #2:

score: 0
Accepted
time: 0ms
memory: 3364kb

input:

1 1

output:

-1 -1

result:

ok no solution

Test #3:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

3 4

output:

8 8
#..#####
#####..#
.##.####
.##.####
#####..#
#..#####
####.##.
####.##.

result:

ok good solution

Test #4:

score: 0
Accepted
time: 0ms
memory: 3452kb

input:

3 5

output:

10 1
#
#
.
#
#
.
#
#
.
.

result:

ok good solution

Test #5:

score: 0
Accepted
time: 0ms
memory: 3416kb

input:

4 5

output:

5 5
##.##
.####
###.#
#.###
####.

result:

ok good solution

Test #6:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

7 10

output:

20 20
......##############
#############......#
######......########
.....##############.
############......##
#####......#########
....##############..
###########......###
####......##########
...##############...
##########......####
###......###########
..##############....
#########......#####
...

result:

ok good solution

Test #7:

score: 0
Accepted
time: 0ms
memory: 3444kb

input:

5 7

output:

14 14
....##########
#########....#
####....######
...##########.
########....##
###....#######
..##########..
#######....###
##....########
.##########...
######....####
#....#########
##########....
#####....#####

result:

ok good solution

Test #8:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

7 9

output:

18 6
..####
###.##
#####.
#..###
####.#
.#####
##..##
#####.
#.####
###..#
.#####
##.###
####..
#.####
###.##
.####.
##.###
####.#

result:

ok good solution

Test #9:

score: 0
Accepted
time: 1ms
memory: 3488kb

input:

0 1

output:

1 1
.

result:

ok good solution

Test #10:

score: 0
Accepted
time: 0ms
memory: 3428kb

input:

1 2

output:

4 1
#
#
.
.

result:

ok good solution

Test #11:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

1 3

output:

6 1
#
#
.
.
.
.

result:

ok good solution

Test #12:

score: 0
Accepted
time: 0ms
memory: 3440kb

input:

1 4

output:

8 1
#
#
.
.
.
.
.
.

result:

ok good solution

Test #13:

score: 0
Accepted
time: 1ms
memory: 3528kb

input:

1 5

output:

10 1
#
#
.
.
.
.
.
.
.
.

result:

ok good solution

Test #14:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

1 6

output:

12 1
#
#
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #15:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

1 7

output:

14 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #16:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

1 8

output:

16 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #17:

score: 0
Accepted
time: 0ms
memory: 3408kb

input:

1 9

output:

18 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #18:

score: 0
Accepted
time: 1ms
memory: 3424kb

input:

1 10

output:

20 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #19:

score: 0
Accepted
time: 0ms
memory: 3500kb

input:

2 5

output:

10 1
#
#
.
#
#
.
.
.
.
.

result:

ok good solution

Test #20:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

2 7

output:

14 1
#
#
.
#
#
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #21:

score: 0
Accepted
time: 0ms
memory: 3456kb

input:

2 9

output:

18 1
#
#
.
#
#
.
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #22:

score: 0
Accepted
time: 0ms
memory: 3420kb

input:

3 7

output:

14 1
#
#
.
#
#
.
#
#
.
.
.
.
.
.

result:

ok good solution

Test #23:

score: 0
Accepted
time: 0ms
memory: 3452kb

input:

3 8

output:

16 1
#
#
.
#
#
.
#
#
.
.
.
.
.
.
.
.

result:

ok good solution

Test #24:

score: 0
Accepted
time: 0ms
memory: 3472kb

input:

3 10

output:

20 1
#
#
.
#
#
.
#
#
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #25:

score: 0
Accepted
time: 0ms
memory: 3532kb

input:

4 7

output:

14 1
#
#
.
#
#
.
#
#
.
#
#
.
.
.

result:

ok good solution

Test #26:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

4 9

output:

18 1
#
#
.
#
#
.
#
#
.
#
#
.
.
.
.
.
.
.

result:

ok good solution

Test #27:

score: 0
Accepted
time: 1ms
memory: 3400kb

input:

5 6

output:

-1 -1

result:

ok no solution

Test #28:

score: 0
Accepted
time: 0ms
memory: 3412kb

input:

5 8

output:

16 1
#
#
.
#
#
.
#
#
.
#
#
.
#
#
.
.

result:

ok good solution

Test #29:

score: 0
Accepted
time: 0ms
memory: 3432kb

input:

5 9

output:

18 1
#
#
.
#
#
.
#
#
.
#
#
.
#
#
.
.
.
.

result:

ok good solution

Test #30:

score: 0
Accepted
time: 0ms
memory: 3492kb

input:

6 7

output:

-1 -1

result:

ok no solution

Test #31:

score: 0
Accepted
time: 0ms
memory: 3460kb

input:

7 8

output:

-1 -1

result:

ok no solution

Test #32:

score: 0
Accepted
time: 1ms
memory: 3452kb

input:

8 9

output:

-1 -1

result:

ok no solution

Test #33:

score: 0
Accepted
time: 0ms
memory: 3384kb

input:

9 10

output:

-1 -1

result:

ok no solution

Extra Test:

score: 0
Extra Test Passed