結果

問題 No.535 自然数の収納方法
ユーザー vjudge1
提出日時 2025-03-18 21:56:28
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 2,308 ms
コンパイル使用メモリ 193,536 KB
実行使用メモリ 35,024 KB
最終ジャッジ日時 2025-03-18 21:56:32
合計ジャッジ時間 3,904 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define sc second
#define pii pair<int,int>
#define pdd pair<double,double>
#define pb push_back
#define umap unordered_map
#define mset multiset
#define pq priority_queue
#define ull unsigned long long
#define i128 __int128
#define ld long double
#define fixs fixed<<setprecision
const int maxn=2000+10;
const int mod=1e9+7;
int n,a[maxn],res,f[maxn][maxn],g[maxn][maxn];
void add(int &x,int y){
    x=(x+y)%mod;
}
int to(int x,int y){
    return min(max(0,x-2)+y,n);
}
void solve(){
    cin>>n;
    for(int i=1;i<=n;i++) f[0][i]=i,g[0][i]=1;
    for(int i=1;i<n;i++){
        for(int j=1;j<=n;j++) f[i][j]=f[i-1][to(i,j)],add(f[i][j],f[i][j-1]);
        for(int j=1;j<=n;j++) g[i][j]=g[i-1][to(i,j)],add(g[i][j],g[i][j-1]);
    }
    cout<<((f[n-1][n]-g[n-1][n]+mod)%mod+g[n-1][n-1])%mod<<endl;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}
/*
Samples
input:

output:

THINGS TODO:
??freopen???????
????
????????????
*/
0