結果

問題 No.1685 One by One
ユーザー 宋来恒宋来恒
提出日時 2023-01-08 16:09:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,960 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 71,672 KB
実行使用メモリ 127,140 KB
最終ジャッジ日時 2023-08-22 02:22:15
合計ジャッジ時間 10,026 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,540 KB
testcase_01 AC 2 ms
5,572 KB
testcase_02 AC 6 ms
20,424 KB
testcase_03 AC 29 ms
74,016 KB
testcase_04 AC 24 ms
41,912 KB
testcase_05 AC 55 ms
89,256 KB
testcase_06 AC 51 ms
112,388 KB
testcase_07 AC 40 ms
77,724 KB
testcase_08 AC 37 ms
93,188 KB
testcase_09 AC 10 ms
34,740 KB
testcase_10 AC 66 ms
114,728 KB
testcase_11 AC 8 ms
26,712 KB
testcase_12 AC 20 ms
59,536 KB
testcase_13 AC 61 ms
83,844 KB
testcase_14 AC 21 ms
51,244 KB
testcase_15 AC 71 ms
81,220 KB
testcase_16 AC 47 ms
116,000 KB
testcase_17 AC 45 ms
110,748 KB
testcase_18 AC 43 ms
106,416 KB
testcase_19 AC 46 ms
112,472 KB
testcase_20 AC 61 ms
106,952 KB
testcase_21 AC 62 ms
109,352 KB
testcase_22 AC 64 ms
111,020 KB
testcase_23 AC 67 ms
114,284 KB
testcase_24 AC 63 ms
110,292 KB
testcase_25 AC 91 ms
116,896 KB
testcase_26 AC 65 ms
113,424 KB
testcase_27 AC 88 ms
111,288 KB
testcase_28 AC 70 ms
117,692 KB
testcase_29 AC 100 ms
117,624 KB
testcase_30 AC 70 ms
117,568 KB
testcase_31 AC 100 ms
117,612 KB
testcase_32 AC 100 ms
117,436 KB
testcase_33 AC 99 ms
117,456 KB
testcase_34 AC 49 ms
117,708 KB
testcase_35 AC 49 ms
117,408 KB
testcase_36 AC 48 ms
117,552 KB
testcase_37 AC 49 ms
117,172 KB
testcase_38 RE -
testcase_39 AC 70 ms
125,652 KB
testcase_40 RE -
testcase_41 AC 70 ms
125,776 KB
testcase_42 RE -
testcase_43 AC 2 ms
5,572 KB
testcase_44 RE -
testcase_45 AC 2 ms
5,548 KB
testcase_46 AC 52 ms
125,656 KB
testcase_47 AC 55 ms
125,720 KB
testcase_48 AC 52 ms
125,636 KB
testcase_49 AC 54 ms
125,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
#define fi first
#define sc second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int N=4005,oo=1e9,mod=1e9+7;
inline int read() {
    int x=0,flag=0;char ch=getchar();
    while(ch<'0'||ch>'9') {flag|=(ch=='-');ch=getchar();}
    while('0'<=ch&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return flag?-x:x;
}
inline int mx(int x,int y) {return x>y?x:y;}
inline int mn(int x,int y) {return x<y?x:y;}
inline void swp(int &x,int &y) {x^=y^=x^=y;}
inline int as(int x) {return x>0?x:-x;}

int n,m,C[N][N],S[N][N];
inline void prep() {
    int L=mx(n,m);
    C[0][0]=S[0][0]=1;
    C[1][0]=C[1][1]=1;S[1][0]=S[1][1]=1;
    for(int i=2;i<=L;++i) {
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;++j)
            C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
        for(int j=0;j<=i;++j)
            S[i][j]=(S[i-2][j]+C[i][j])%mod;
    }
}
inline void solve_odd() {
    int ans=0,L=n/2;
    for(int i=0;i<=L;++i)
        for(int j=0;j<=L;++j) {
            if(i==0&&j==0) continue;
            ans=(ans+1ll*C[n][i]*C[n-i][j]%mod*S[m-1][i+j-1])%mod;
            if(i<=j) {
                if(m-n-i+j<0) continue;
                ans=(ans+1ll*C[n][i]*C[n-i][j]%mod*S[m-n-i+j+(i+j-1)][i+j-1])%mod;
            } else {
                if(m-n-j+i<0) continue;
                ans=(ans+1ll*C[n][i]*C[n-i][j]%mod*S[m-n-j+i+(i+j-1)][i+j-1])%mod;
            }
        }
    if(m%2==0||m>=n) ans=(ans+1)%mod;
    printf("%d\n",ans);
}
inline void solve_even() {
    int ans=0,L=n/2;
    for(int i=0;i<=L;++i)
        for(int j=0;j<L;++j) {
            if(i==0&&j==0) continue;
            ans=(ans+1ll*C[n][i]*C[n-i][j]%mod*S[m-1][i+j-1])%mod;
        }
    if(m%2==0) ans=(ans+1)%mod;
    printf("%d\n",ans);
}
int main() {
    n=read();m=read();
    prep();
    if(n&1) solve_odd();
    else solve_even();
    return 0;
}
0