結果

問題 No.1684 Find Brackets
ユーザー chocoruskchocorusk
提出日時 2021-09-17 23:05:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,807 bytes
コンパイル時間 3,441 ms
コンパイル使用メモリ 189,088 KB
実行使用メモリ 38,824 KB
最終ジャッジ日時 2023-09-12 09:08:32
合計ジャッジ時間 5,914 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
38,708 KB
testcase_01 AC 48 ms
38,516 KB
testcase_02 AC 70 ms
38,516 KB
testcase_03 AC 48 ms
38,500 KB
testcase_04 AC 48 ms
38,716 KB
testcase_05 AC 48 ms
38,500 KB
testcase_06 AC 48 ms
38,712 KB
testcase_07 AC 68 ms
38,588 KB
testcase_08 AC 65 ms
38,608 KB
testcase_09 AC 53 ms
38,544 KB
testcase_10 AC 52 ms
38,576 KB
testcase_11 AC 51 ms
38,508 KB
testcase_12 AC 60 ms
38,504 KB
testcase_13 AC 67 ms
38,504 KB
testcase_14 WA -
testcase_15 AC 55 ms
38,596 KB
testcase_16 WA -
testcase_17 AC 70 ms
38,504 KB
testcase_18 AC 71 ms
38,516 KB
testcase_19 WA -
testcase_20 AC 48 ms
38,516 KB
testcase_21 AC 55 ms
38,500 KB
testcase_22 AC 55 ms
38,648 KB
testcase_23 AC 56 ms
38,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint1000000007;
mint f[4000010], invf[4000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i;
    invf[n]=f[n].inv();
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1);
}
mint comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]*invf[x-y];
}
int n, m;
mint x[1000010];
int main()
{
    cin>>n>>m;
    fac(4000000);
    mint ans=0;
    for(int i=m; i<=n; i++){
        ans+=comb(n, i)*n;
    }
    for(int d=1; d<=n; d++){
        // for(int i=m; i<=(n-d)/2; i++){
        //     x[d]+=comb(n, i);
        // }
        if((n-d)/2>(n-d-1)/2 && m<=(n-d)/2){
            ans+=d*comb(n, (n-d)/2);
        }
        int l1=min(n-d-m, n-d-(n-d)/2-1), l2=min(n-d-m-1, n-d-1-(n-d-1)/2-1);
        if(l1>l2 && l1>=0){
            ans+=d*comb(n, l1);
        }
        // for(int i=0; i<=n-d-m && i<n-d-(n-d)/2; i++){
        //     x[d]+=comb(n, i);
        // }
    }
    //cout<<ans.val()<<endl;
    for(int d=1; d<=n; d++){
        // for(int i=0; i<=(n-d)/2 && i<=n-m; i++){
        //     x[d]+=comb(n, i);
        // }
        if((n-d+2)/2>(n-d+1)/2 && (n-d)/2<=n-m){
            ans+=d*comb(n, (n-d)/2);
        }
        if(max(0, m-d)!=max(0, m-d-1) && max(0, m-d-1)<=n-d-(n-d)/2-1){
            ans-=d*comb(n, max(0, m-d-1));
        }
        if(n-d+2-(n-d+2)/2>n-d+1-(n-d+1)/2 && max(0, m-d-1)<=n-d-(n-d)/2-1){
            ans+=d*comb(n, n-d-(n-d)/2-1);
        }
        // for(int i=max(0, m-d); i<n-d-(n-d)/2; i++){
        //     x[d]+=comb(n, i);
        // }
    }
    // for(int d=1; d<=n; d++){
    //     ans+=d*(x[d]-x[d+1]);
    // }
    // for(int d=1; d<=n; d++){
    //     if(d<n && (n-d-1)/2!=(n-d-2)/2 && m<=(n-d-1)/2){
    //         ans+=d*comb(n, (n-d-1)/2);
    //     }
    //     int l1=min(n-d-m, (n-d)/2), l2=min(n-d-m-1, (n-d-1)/2);
    //     if(l1>l2) ans+=d*comb(n, l1);
    // }
    // for(int d=1; d<=n; d++){
    //     if(d<n && (n-d-1)/2!=(n-d-2)/2 && (n-d-1)/2<=n-m){
    //         ans+=d*comb(n, (n-d-1)/2);
    //     }
    //     if(m-d-1<=(n-d-1)/2) ans-=d*comb(n, m-d-1);
    //     if((n-d)/2!=(n-d-1)/2 && m-d<=(n-d)/2) ans+=d*comb(n, (n-d)/2);
    // }
    cout<<ans.val()<<endl;
    return 0;
}
0