結果

問題 No.1685 One by One
ユーザー 宋来恒宋来恒
提出日時 2023-01-08 16:10:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,943 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 71,416 KB
実行使用メモリ 460,888 KB
最終ジャッジ日時 2023-08-22 02:23:10
合計ジャッジ時間 11,340 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,552 KB
testcase_01 AC 2 ms
5,532 KB
testcase_02 AC 9 ms
40,688 KB
testcase_03 AC 70 ms
119,300 KB
testcase_04 AC 42 ms
91,556 KB
testcase_05 AC 176 ms
213,036 KB
testcase_06 AC 106 ms
186,008 KB
testcase_07 AC 95 ms
159,160 KB
testcase_08 AC 57 ms
113,916 KB
testcase_09 AC 23 ms
65,708 KB
testcase_10 AC 265 ms
309,844 KB
testcase_11 AC 18 ms
59,092 KB
testcase_12 AC 33 ms
39,012 KB
testcase_13 AC 121 ms
192,352 KB
testcase_14 AC 44 ms
86,144 KB
testcase_15 AC 186 ms
270,096 KB
testcase_16 AC 74 ms
141,180 KB
testcase_17 AC 70 ms
134,196 KB
testcase_18 AC 69 ms
131,032 KB
testcase_19 AC 69 ms
133,312 KB
testcase_20 AC 84 ms
127,360 KB
testcase_21 AC 84 ms
128,856 KB
testcase_22 AC 91 ms
138,244 KB
testcase_23 AC 94 ms
142,148 KB
testcase_24 AC 213 ms
314,132 KB
testcase_25 AC 261 ms
335,492 KB
testcase_26 AC 229 ms
331,708 KB
testcase_27 AC 247 ms
319,712 KB
testcase_28 AC 257 ms
355,292 KB
testcase_29 AC 289 ms
358,176 KB
testcase_30 AC 256 ms
358,188 KB
testcase_31 AC 313 ms
358,176 KB
testcase_32 AC 283 ms
362,624 KB
testcase_33 AC 271 ms
460,888 KB
testcase_34 AC 75 ms
245,964 KB
testcase_35 AC 75 ms
245,752 KB
testcase_36 AC 75 ms
245,748 KB
testcase_37 AC 74 ms
245,032 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
権限があれば一括ダウンロードができます

ソースコード

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=8005,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() {
    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<=m+n;++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