提出 #44635415
ソースコード 拡げる
// LUOGU_RID: 121207161
#include<bits/stdc++.h>
#define LL long long
#define DB double
int MOD;
#define ls(x) x << 1
#define rs(x) x << 1 | 1
#define lowbit(x) x & (-x)
#define PII pair<int, int>
#define MP make_pair
#define VI vector<int>
#define VII vector<int>::iterator
#define all(x) x.begin(), x.end()
#define EB emplace_back
#define SI set<int>
#define SII set<int>::iterator
#define QI queue<int>
using namespace std;
template<typename T> void chkmn(T &a, const T &b) { (a > b) && (a = b); }
template<typename T> void chkmx(T &a, const T &b) { (a < b) && (a = b); }
int inc(const int &a, const int &b) { return a + b >= MOD ? a + b - MOD : a + b; }
int dec(const int &a, const int &b) { return a - b < 0 ? a - b + MOD : a - b; }
int mul(const int &a, const int &b) { return 1LL * a * b % MOD; }
int sqr(const int &a) { return 1LL * a * a % MOD; }
void Inc(int &a, const int &b) { ((a += b) >= MOD) && (a -= MOD); }
void Dec(int &a, const int &b) { ((a -= b) < 0) && (a += MOD); }
void Mul(int &a, const int &b) { a = 1LL * a * b % MOD; }
void Sqr(int &a) { a = 1LL * a * a % MOD; }
int qwqmi(int x, int k = MOD - 2)
{
int res = 1;
while(k)
{
if(k & 1) Mul(res, x);
Sqr(x), k >>= 1;
}
return res;
}
const int N = 105;
int n, K, ans;
int f[2][N][N][N];
int s[N][N][N];
int main()
{
scanf("%d %d %d", &n, &K, &MOD);
int now = 1, lst = 0;
f[1][1][1][0] = 1;
for(int x = 1; x <= 2; ++x)
for(int y = 1; y <= 2; ++y)
{
int val = f[now][x][y][0];
Dec(val, s[x - 1][y][0]);
Dec(val, s[x][y - 1][0]);
Inc(val, s[x - 1][y - 1][0]);
s[x][y][0] = val;
}
for(int i = 1; i < n; ++i)
{
swap(now, lst);
memset(f[now], 0, sizeof(f[now]));
for(int w = 0; w < i; ++w)
for(int a = 1; a <= i + 1; ++a)
for(int b = 1; b <= i + 1; ++b)
{
auto get = [&](int xl, int yl, int xr, int yr)
{
int val = s[xr][yr][w];
Dec(val, s[xl - 1][yr][w]);
Dec(val, s[xr][yl - 1][w]);
Inc(val, s[xl - 1][yl - 1][w]);
return val;
};
if(a >= 2 && b <= i) Inc(f[now][a][b][w], get(1, b, a - 1, i));
if(a <= i && b >= 2) Inc(f[now][a][b][w], get(a, 1, i, b - 1));
if(a >= 2 && b >= 2) Inc(f[now][a][b][w + 1], get(1, 1, a - 1, b - 1));
if(a <= i && b <= i) Inc(f[now][a][b][w + 1], get(a, b, i, i));
}
for(int w = 0; w <= i; ++w)
for(int x = 1; x <= i + 1; ++x)
for(int y = 1; y <= i + 1; ++y)
{
int val = f[now][x][y][w];
Inc(val, s[x - 1][y][w]);
Inc(val, s[x][y - 1][w]);
Dec(val, s[x - 1][y - 1][w]);
s[x][y][w] = val;
}
}
for(int x = 1; x <= n; ++x)
for(int y = 1; y <= n; ++y)
Inc(ans, f[now][x][y][K]);
printf("%d\n", ans);
return 0;
}
提出情報
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:45:7: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
45 | scanf("%d %d %d", &n, &K, &MOD);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
600 / 600 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_01.txt, 00_sample_02.txt |
| All |
00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_01.txt |
AC |
14 ms |
12704 KiB |
| 00_sample_02.txt |
AC |
48 ms |
13832 KiB |
| 01_test_01.txt |
AC |
10 ms |
8184 KiB |
| 01_test_02.txt |
AC |
15 ms |
8052 KiB |
| 01_test_03.txt |
AC |
575 ms |
16868 KiB |
| 01_test_04.txt |
AC |
560 ms |
16932 KiB |
| 01_test_05.txt |
AC |
570 ms |
16924 KiB |
| 01_test_06.txt |
AC |
29 ms |
13368 KiB |
| 01_test_07.txt |
AC |
13 ms |
12596 KiB |
| 01_test_08.txt |
AC |
75 ms |
14268 KiB |
| 01_test_09.txt |
AC |
202 ms |
15508 KiB |
| 01_test_10.txt |
AC |
341 ms |
16292 KiB |
| 01_test_11.txt |
AC |
342 ms |
16272 KiB |
| 01_test_12.txt |
AC |
535 ms |
16844 KiB |
| 01_test_13.txt |
AC |
478 ms |
16836 KiB |
| 01_test_14.txt |
AC |
357 ms |
16356 KiB |
| 01_test_15.txt |
AC |
440 ms |
16836 KiB |
| 01_test_16.txt |
AC |
449 ms |
16632 KiB |
| 01_test_17.txt |
AC |
460 ms |
16876 KiB |
| 01_test_18.txt |
AC |
417 ms |
16652 KiB |