Submission #23263864
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
int mod = 998244353;
int add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
template<class... T> int add(int x, T... y) { return add(x, add(y...)); }
int mul(int x, int y) { return 1LL * x * y % mod; }
template<class... T> int mul(int x, T... y) { return mul(x, mul(y...)); }
int sub(int x, int y) { return add(x, mod - y); }
int modpow(int a, long long b) {
int ret = 1; while (b > 0) {
if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
} return ret;
}
int modinv(int a) { return modpow(a, mod - 2); }
typedef vector<int> Vec;
typedef vector<Vec> Mat;
Vec mulMatVec(Mat a, Vec b)
{
int n = b.size(); Vec ret(n, 0);
rep(i, 0, n) rep(j, 0, n) ret[i] = add(ret[i], mul(a[i][j], b[j]));
return ret;
}
Mat mulMatMat(Mat a, Mat b)
{
int n = a.size(); Mat ret(n, Vec(n, 0));
rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) ret[i][j] = add(ret[i][j], mul(a[i][k], b[k][j]));
return ret;
}
Mat fastpow(Mat x, ll n)
{
Mat ret(x.size(), Vec(x.size(), 0));
rep(i, 0, x.size()) ret[i][i] = 1;
while (0 < n) { if ((n % 2) == 0) { x = mulMatMat(x, x); n >>= 1; } else { ret = mulMatMat(ret, x); --n; } }
return ret;
}
void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
void printMat(Mat a) { rep(i, 0, a.size()) printVec(a[i]); }
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i @hamayanhamayan0
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
int H; ll W;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> H >> W;
Mat m(1 << H, Vec(1 << H, 0));
Vec v(1 << H, 0);
Vec init(1 << H, 0);
rep(msk, 0, 1 << H) {
bool nextPlace = false;
bool ok = true;
rep(i, 0, H) {
if (nextPlace) {
if (msk & (1 << i)) nextPlace = false;
else ok = false;
}
else {
if (msk & (1 << i)) nextPlace = true;
}
}
if (nextPlace) ok = false;
if (ok) {
init[msk] = 1;
}
}
rep(msk, 0, 1 << H) v[msk] = init[msk];
rep(from, 0, 1 << H) rep(to, 0, 1 << H) {
rep(used, 0, 1 << H) {
bool ok = true;
rep(i, 0, H) if (used & (1 << i)) {
if ((from & (1 << i)) || (to & (1 << i))) ok = false;
}
if (ok) {
int to2 = to;
rep(i, 0, H) if (used & (1 << i)) to2 += 1 << i;
m[to2][from] = add(m[to2][from], init[to]);
}
}
}
m = fastpow(m, W - 1);
v = mulMatVec(m, v);
int ans = 0;
rep(msk, 0, 1 << H) ans = add(ans, v[msk]);
cout << ans << endl;
}
Submission Info
Submission Time
2021-06-07 02:40:06+0900
Task
F - Hanjo 2
User
hamayanhamayan
Language
C++ (GCC 9.2.1)
Score
600
Code Size
4015 Byte
Status
AC
Exec Time
165 ms
Memory
3768 KiB
Compile Error
./Main.cpp: In function ‘int modpow(int, long long int)’:
./Main.cpp:21:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
21 | if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
| ^~
./Main.cpp:21:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
21 | if (b & 1) ret = 1LL * ret * a % mod; a = 1LL * a * a % mod; b >>= 1;
| ^
./Main.cpp: In function ‘Mat fastpow(Mat, ll)’:
./Main.cpp:2:33: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::vector<int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
2 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
42 | rep(i, 0, x.size()) ret[i][i] = 1;
| ~~~~~~~~~~~~~~
./Main.cpp:42:5: note: in expansion of macro ‘rep’
42 | rep(i, 0, x.size()) ret[i][i] = 1;
| ^~~
./Main.cpp: In function ‘void printVec(Vec)’:
./Main.cpp:2:33: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
2 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
46 | void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
| ~~~~~~~~~~~~~~
./Main.cpp:46:39: note: in expansion of macro ‘rep’
46 | void printVec(Vec a) { cout << "[\t"; rep(i, 0, a.size()) cout << a[i] << "\t"; cout << "]" << endl; }
| ^~~
./Main.cpp: In function ‘void printMat(Mat)’:
./Main.cpp:2:33: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<std::vector<int> >::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
2 | #define rep(i,a,b) for(int i=a;i<b;i++)
......
47 | void printMat(Mat a) { rep(i, 0, ...
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
600 / 600
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt, sample_03.txt
All
hand_01.txt, max_01.txt, max_02.txt, max_03.txt, max_04.txt, max_05.txt, max_06.txt, max_07.txt, max_08.txt, max_09.txt, max_10.txt, max_11.txt, max_12.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name
Status
Exec Time
Memory
hand_01.txt
AC
7 ms
3644 KiB
max_01.txt
AC
3 ms
3512 KiB
max_02.txt
AC
2 ms
3560 KiB
max_03.txt
AC
3 ms
3660 KiB
max_04.txt
AC
8 ms
3620 KiB
max_05.txt
AC
35 ms
3592 KiB
max_06.txt
AC
165 ms
3720 KiB
max_07.txt
AC
2 ms
3612 KiB
max_08.txt
AC
2 ms
3516 KiB
max_09.txt
AC
3 ms
3524 KiB
max_10.txt
AC
9 ms
3452 KiB
max_11.txt
AC
31 ms
3640 KiB
max_12.txt
AC
164 ms
3768 KiB
random_01.txt
AC
2 ms
3588 KiB
random_02.txt
AC
3 ms
3608 KiB
random_03.txt
AC
2 ms
3568 KiB
random_04.txt
AC
3 ms
3516 KiB
random_05.txt
AC
6 ms
3588 KiB
random_06.txt
AC
24 ms
3768 KiB
random_07.txt
AC
2 ms
3660 KiB
random_08.txt
AC
2 ms
3584 KiB
random_09.txt
AC
2 ms
3608 KiB
random_10.txt
AC
2 ms
3588 KiB
random_11.txt
AC
7 ms
3608 KiB
random_12.txt
AC
16 ms
3668 KiB
random_13.txt
AC
2 ms
3524 KiB
random_14.txt
AC
8 ms
3620 KiB
random_15.txt
AC
33 ms
3540 KiB
random_16.txt
AC
3 ms
3612 KiB
random_17.txt
AC
2 ms
3460 KiB
random_18.txt
AC
2 ms
3512 KiB
random_19.txt
AC
6 ms
3656 KiB
random_20.txt
AC
30 ms
3688 KiB
random_21.txt
AC
2 ms
3512 KiB
random_22.txt
AC
2 ms
3564 KiB
random_23.txt
AC
2 ms
3612 KiB
random_24.txt
AC
6 ms
3688 KiB
random_25.txt
AC
32 ms
3640 KiB
random_26.txt
AC
164 ms
3672 KiB
random_27.txt
AC
4 ms
3512 KiB
random_28.txt
AC
2 ms
3524 KiB
random_29.txt
AC
2 ms
3520 KiB
random_30.txt
AC
8 ms
3616 KiB
random_31.txt
AC
29 ms
3540 KiB
random_32.txt
AC
161 ms
3700 KiB
sample_01.txt
AC
2 ms
3644 KiB
sample_02.txt
AC
2 ms
3512 KiB
sample_03.txt
AC
12 ms
3540 KiB