QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408196#6425. Harmonious RectangleNelofus#AC ✓3ms3608kbC++202.9kb2024-05-09 20:06:142024-05-09 20:06:15

Judging History

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

  • [2024-05-09 20:06:15]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3608kb
  • [2024-05-09 20:06:14]
  • 提交

answer

/*
 * Copyright© 2024 Heratino & Nelofus. All rights reserved.
 * author: Heratino & Nelofus
 * Problem: 
 * Tag: 
 * Memory Limit: 
 * Time Limit: 
 * Source: 
 */

// Narcissus & どうか安寧な記憶を

#include <bits/stdc++.h>
using i64 = long long;

//{{{星光闪耀
template<typename Ta, typename Tb>
inline void chkmax(Ta &a, const Tb &b) {if (a < b)	a = b;}
template<typename Ta, typename Tb>
inline void chkmin(Ta &a, const Tb &b) {if (a > b)	a = b;}
//}}}

constexpr int N = 10;
constexpr int mod = 1e9 + 7;

inline i64 f_pow(i64 a, int k) {
	i64 base = 1;
	for (; k; k >>= 1, a = 1ll * a * a % mod)
		if (k & 1)
			base = base * a % mod;
	return base;
}

inline int Minu(const int &x, const int &y) {
	return x - y < 0 ? x - y + mod : x - y;
}
inline int Plus(const int &x, const int &y) {
	return x - y >= mod ? x + y - mod : x + y;
}

int col[N][N];
int counter = 0;
void dfs(int x, int y, int mx, int my) {
	for (int k = 0; k < 3; k++) {
		col[x][y] = k;
		bool flag = true;
		for (int i = 1; i < x; i++) {
			for (int j = 1; j < y; j++) {
				if (col[i][j] == col[i][y] && col[x][j] == col[x][y]) {
					flag = false;
				}
				if (col[i][j] == col[x][j] && col[i][y] == col[x][y]) {
					flag = false;
				}
				if (!flag)
					break;
			}
			if (!flag)
				break;
		}
		if (flag)  {
			if (y == my) {
				if (x == mx) {
					counter++;
				} else {
					dfs(x + 1, 1, mx, my);
				}
			} else {
				dfs(x, y + 1, mx, my);
			}
		}
	}
}

int solve(int n, int m) {
	counter = 0;
	dfs(1, 1, n, m);
	return Minu(f_pow(3, n * m), counter);
	//	return counter;
}
int answer[N][N] = {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 15, 339, 4761, 52929, 517761, 4767849, 43046721, 387420489, 486784380}, {0, 339, 16485, 518265, 14321907, 387406809, 460338013, 429534507, 597431612, 130653412}, {0, 4761, 518265, 43022385, 486780060, 429534507, 792294829, 175880701, 246336683, 953271190}, {0, 52929, 14321907, 486780060, 288599194, 130653412, 748778899, 953271190, 644897553, 710104287}, {0, 517761, 387406809, 429534507, 130653412, 246336683, 579440654, 412233812, 518446848, 947749553}, {0, 4767849, 460338013, 792294829, 748778899, 579440654, 236701429, 666021604, 589237756, 662963356}, {0, 43046721, 429534507, 175880701, 953271190, 412233812, 666021604, 767713261, 966670169, 322934415}, {0, 387420489, 597431612, 246336683, 644897553, 518446848, 589237756, 966670169, 968803245, 954137859}, {0, 486784380, 130653412, 953271190, 710104287, 947749553, 662963356, 322934415, 954137859, 886041711}};

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int T;
	std::cin >> T;
	while (T--) {
		int n, m;
		std::cin >> n >> m;
		if (n == 1 || m == 1) {
			std::cout << "0" << '\n';
		} else if (n <= 10 && m <= 10) {
			std::cout << answer[n - 1][m - 1] << '\n';
		} else {
			std::cout << f_pow(3, n * m) << '\n';
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1 4
2 2
3 3

output:

0
15
16485

result:

ok 3 number(s): "0 15 16485"

Test #2:

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

input:

10000
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
1 20
1 21
1 22
1 23
1 24
1 25
1 26
1 27
1 28
1 29
1 30
1 31
1 32
1 33
1 34
1 35
1 36
1 37
1 38
1 39
1 40
1 41
1 42
1 43
1 44
1 45
1 46
1 47
1 48
1 49
1 50
1 51
1 52
1 53
1 54
1 55
1 56
1 57
1 58
1 59
1 60
1 6...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
15
339
4761
52929
517761
4767849
43046721
387420489
486784380
381059392
429534507
865810542
792294...

result:

ok 10000 numbers

Test #3:

score: 0
Accepted
time: 3ms
memory: 3524kb

input:

10000
1705 810
454 699
1749 1057
1177 326
132 74
1657 1927
1688 781
1870 1278
261 681
901 1166
740 1088
1762 344
1519 1027
887 1049
1871 1800
533 173
873 1725
1960 1555
1582 628
1197 453
1668 810
1882 468
1163 1011
1077 627
438 113
1150 480
927 407
1393 1348
784 1650
198 903
939 1930
173 1726
1276 1...

output:

4664542
474135175
453284040
865070735
892936842
930878193
929505944
730204219
878002827
776271982
319486673
354630833
31019262
653603083
316945266
163467758
910052980
502234498
692029941
37337160
838442854
94243481
112835966
363282856
563398619
682187998
379850832
751053515
449670075
419120473
96439...

result:

ok 10000 numbers

Test #4:

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

input:

10000
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 7
3 ...

output:

460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
460338013
...

result:

ok 10000 numbers