QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#351839 | #6425. Harmonious Rectangle | PorNPtree# | WA | 228ms | 3940kb | C++14 | 2.8kb | 2024-03-12 16:05:51 | 2024-03-12 16:05:51 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7;
int ksm(int y)
{
int x = 3, res = 1;
while (y) {
if (y & 1) {
res = 1ll * res * x % P;
}
x = 1ll * x * x % P;
y >>= 1;
}
return res;
}
int n, m, a[25][25], res;
void dfs(int x, int y)
{
int chk = 0;
for (int i = 1; i <= n && !chk; ++i) {
for (int k = 1; k <= m && !chk; ++k) {
if (!a[i][k]) {
continue;
}
for (int j = i + 1; j <= n; ++j) {
for (int l = k + 1; l <= m; ++l) {
if (a[j][l]) {
chk |= ((a[i][k] == a[i][l]) && (a[j][k] == a[j][l]));
chk |= ((a[i][k] == a[j][k]) && (a[i][l] == a[j][l]));
}
}
}
}
}
if (chk) {
int ct = (n - x) * m + m - y + 1;
((res += ksm(ct)) >= P) && (res -= P);
return;
}
if (x > n) {
// for (int i = 1; i <= n; ++i) {
// for (int j = 1; j <= m; ++j) {
// printf("%d", a[i][j]);
// }
// puts("");
// }
// puts("");
return;
}
for (int i = 1; i <= 3; ++i) {
a[x][y] = i;
if (y == m) {
dfs(x + 1, 1);
} else {
dfs(x, y + 1);
}
a[x][y] = 0;
}
return;
}
signed main()
{
int T;
scanf("%d", &T);
while (T--) {
scanf("%d%d", &n, &m);
if (n > m) {
swap(n, m);
}
if (n == 1) {
puts("0");
continue;
}
if (m >= 8) {
printf("%d\n", ksm(n * m));
continue;
}
if (n == 2 && m == 7) {
puts("4767849");
continue;
}
if (n >= 3 && m >= 7) {
printf("%d\n", ksm(n * m));
continue;
}
if (n == 3 && m == 5) {
puts("14321907");
continue;
}
if (n == 3 && m == 6) {
puts("387406809");
continue;
}
if (n == 3 && m == 7) {
puts("460338013");
continue;
}
if (n == 4 && m == 4) {
puts("43022385");
continue;
}
if (n == 4 && m == 5) {
puts("486780060");
continue;
}
if (n >= 4 && m >= 6) {
printf("%d\n", ksm(n * m));
continue;
}
if (n == 5 && m == 6) {
puts("288599194");
continue;
}
res = 0;
dfs(1, 1);
printf("%d\n", res);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3788kb
input:
3 1 4 2 2 3 3
output:
0 15 16485
result:
ok 3 number(s): "0 15 16485"
Test #2:
score: -100
Wrong Answer
time: 228ms
memory: 3940kb
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:
wrong answer 207th numbers differ - expected: '460338013', found: '460353133'