結果
| 問題 |
No.1761 Sequence Distance
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-07-21 23:44:00 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,405 ms / 8,000 ms |
| コード長 | 1,625 bytes |
| コンパイル時間 | 2,875 ms |
| コンパイル使用メモリ | 277,184 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-07-21 23:44:17 |
| 合計ジャッジ時間 | 16,079 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 42 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define i64 long long
const int mod=998244353;
static int dp[2][70][1005], diffArr[70];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n,m; cin>>n>>m;
int off=int(sqrt(m))+1, rows=2*off+2;
for(int i=0;i<rows;i++) diffArr[i]=abs(i-off);
int cur=0, nxt=1;
// init
for(int i=0;i<rows;i++) for(int j=0;j<=m;j++) dp[cur][i][j]=0;
dp[cur][off][0]=1;
for(int step=0; step<n; step++){
// clear next 层
for(int i=0;i<rows;i++) for(int j=0;j<=m;j++) dp[nxt][i][j]=0;
// 转移
for(int i=0;i<rows-1;i++){
int* row = dp[cur][i];
int* mid = dp[nxt][i];
int* down= dp[nxt][i+1];
int d0 = diffArr[i], d2 = diffArr[i+1];
for(int j=0;j<=m;j++){
int v = row[j]; if(!v) continue;
if(i>0){
int t = j + diffArr[i-1];
if(t<=m){
dp[nxt][i-1][t] += v;
if(dp[nxt][i-1][t]>=mod) dp[nxt][i-1][t]-=mod;
}
}
int t = j + d0;
if(t<=m){
mid[t] += v;
if(mid[t]>=mod) mid[t]-=mod;
mid[t] += v;
if(mid[t]>=mod) mid[t]-=mod;
}
t = j + d2;
if(t<=m){
down[t] += v;
if(down[t]>=mod) down[t]-=mod;
}
}
}
cur^=1; nxt^=1;
}
cout<<dp[cur][off][m];
return 0;
}