QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589874 | #6425. Harmonious Rectangle | ji_114514 | WA | 343ms | 3596kb | C++20 | 1.4kb | 2024-09-25 20:26:56 | 2024-09-25 20:26:58 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e3 + 10, mod = 1e9 + 7;
ll dp[20][20];
ll qmi(ll a, ll k)
{
ll res = 1;
while (k)
{
if (k & 1)res = res * a;
k >>= 1;
a = a * a;
}
return res;
}
int n, m, c[20][20];
bool check(int x, int y)
{
for (int i = 1; i < x; i++)
{
for (int j = 1; j < y; j++)
{
if ((c[i][j] == c[i][y]) && (c[x][j] == c[x][y]))return 0;
if ((c[i][j] == c[x][j]) && (c[i][y] == c[x][y]))return 0;
}
}
return 1;
}
void dfs(int x, int y)
{
if (y == m + 1) {
y = 1, x++;
if (x > n) {
dp[n][m]++;
return;
}
}
for (int i = 0; i < 3; i++) {
c[x][y] = i;
if (check(x, y))dfs(x, y + 1);
}
}
void solve()
{
int n, m; cin >> n >> m;
if (n > m)swap(n, m);
if (m < 10)cout << dp[n][m] << '\n';
else cout << qmi(3, n * m) << '\n';
}
int main()
{
for (int i = 1; i < 10; i++)
{
for (int j = i; j < 10; j++)
{
n = i, m = j;
if (i >= 4 && j >= 7)continue;
dfs(1, 1);
dp[i][j] = (qmi(3, i * j) - dp[i][j]) % mod;
}
}
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1; cin >> t;
while (t--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 343ms
memory: 3584kb
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: 343ms
memory: 3596kb
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 59049 177147 531441 1594323 4782969 14348907 43046721 129140163 387420489 1162261467 3486784401 10460353203 31381059609 94143178827 282429536481 847288609443 2541865828329 7625597484987 22876792454961 68630377364883 205891132094649 617673396283947 1853020188851841 5559060566555523 ...
result:
wrong answer 10th numbers differ - expected: '0', found: '59049'