結果
| 問題 | No.3600 Moving Queen Many Times |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-07-24 22:35:51 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 598 ms / 7,000 ms |
| + 969µs | |
| コード長 | 1,704 bytes |
| 記録 | |
| コンパイル時間 | 1,965 ms |
| コンパイル使用メモリ | 203,544 KB |
| 実行使用メモリ | 74,368 KB |
| 最終ジャッジ日時 | 2026-07-24 22:36:07 |
| 合計ジャッジ時間 | 9,066 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 75 |
ソースコード
#include <iostream>
#include <ranges>
#include <algorithm>
#include <vector>
#include <atcoder/modint>
using mint=atcoder::modint998244353;
using namespace std;
using ll=long long;
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int h,w;
cin>>h>>w;
vector<vector<bool>> graph(h*w,vector<bool>(h*w));
for(int i=0;i<h;i++)for(int j=0;j<w;j++){
for(int ni=0;ni<h;ni++)for(int nj=0;nj<w;nj++){
if(i==ni&&j==nj)continue;
if(i==ni||j==nj||i+j==ni+nj||i-j==ni-nj)graph[i*w+j][ni*w+nj]=true;
}
}
vector dp(h*w,vector(h*w,vector<mint>(1<<(h*w))));
for(int i=0;i<h*w;i++){
dp[i][i][0]=1;
for(int j=0;j<(1<<(h*w));j++){
for(int k=0;k<h*w;k++){
if(dp[i][k][j]==0)continue;
for(int l=0;l<h*w;l++){
if(graph[k][l]&&(j>>l&1)==0)dp[i][l][j+(1<<l)]+=dp[i][k][j];
}
}
}
}
vector<vector<mint>> mat(h*w,vector<mint>(h*w));
for(int i=0;i<h*w;i++)for(int j=0;j<h*w;j++){
mat[i][j]=dp[i][j][(1<<(h*w))-1];
}
int sx,sy,gx,gy;
ll k;
cin>>sx>>sy>>gx>>gy>>k;
sx--;sy--;gx--;gy--;
ll kq=k/(h*w),kr=k%(h*w);
vector<vector<mint>> res(h*w,vector<mint>(h*w));
for(int i=0;i<h*w;i++)res[i][i]=1;
while(kq>0){
if(kq&1){
vector<vector<mint>> nres(h*w,vector<mint>(h*w));
for(int i=0;i<h*w;i++)for(int j=0;j<h*w;j++)for(int k=0;k<h*w;k++)nres[i][j]+=res[i][k]*mat[k][j];
res=nres;
}
vector<vector<mint>> nmat(h*w,vector<mint>(h*w));
for(int i=0;i<h*w;i++)for(int j=0;j<h*w;j++)for(int k=0;k<h*w;k++)nmat[i][j]+=mat[i][k]*mat[k][j];
mat=nmat;
kq>>=1;
}
mint ans=0;
int s=sx*w+sy,g=gx*w+gy;
for(int i=0;i<h*w;i++){
for(int j=0;j<(1<<(h*w));j++){
if(__builtin_popcount(j)==kr)ans+=res[s][i]*dp[i][g][j];
}
}
cout<<ans.val()<<endl;
}