結果

問題 No.2512 Mountain Sequences
ユーザー maksimmaksim
提出日時 2023-10-20 22:53:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 862 ms / 3,000 ms
コード長 1,536 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 176,400 KB
実行使用メモリ 20,776 KB
最終ジャッジ日時 2023-10-20 22:53:30
合計ジャッジ時間 20,268 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 149 ms
10,420 KB
testcase_01 AC 157 ms
10,420 KB
testcase_02 AC 146 ms
10,420 KB
testcase_03 AC 142 ms
10,420 KB
testcase_04 AC 150 ms
10,420 KB
testcase_05 AC 151 ms
10,420 KB
testcase_06 AC 147 ms
10,416 KB
testcase_07 AC 144 ms
10,420 KB
testcase_08 AC 148 ms
10,412 KB
testcase_09 AC 157 ms
10,412 KB
testcase_10 AC 820 ms
20,344 KB
testcase_11 AC 847 ms
20,504 KB
testcase_12 AC 848 ms
20,688 KB
testcase_13 AC 831 ms
20,412 KB
testcase_14 AC 846 ms
20,696 KB
testcase_15 AC 862 ms
20,776 KB
testcase_16 AC 853 ms
20,416 KB
testcase_17 AC 816 ms
20,584 KB
testcase_18 AC 826 ms
20,460 KB
testcase_19 AC 836 ms
20,440 KB
testcase_20 AC 564 ms
19,656 KB
testcase_21 AC 565 ms
19,944 KB
testcase_22 AC 594 ms
19,892 KB
testcase_23 AC 569 ms
19,504 KB
testcase_24 AC 559 ms
19,612 KB
testcase_25 AC 453 ms
19,388 KB
testcase_26 AC 809 ms
19,388 KB
testcase_27 AC 599 ms
19,388 KB
testcase_28 AC 620 ms
19,120 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int32_t main()':
main.cpp:49:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   49 |         auto [n,m]=que[i];
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
const int p=998244353;
int po(int a,int b) {if(b==0) return 1; if(b==1) return a; if(b%2==0) {int u=po(a,b/2);return (u*u)%p;} else {int u=po(a,b-1);return (a*u)%p;}}
int inv(int x) {return po(x,p-2);}
const int maxn=4e5+5;
int fact[maxn];int invf[maxn];
int c(int n,int k)
{
    if(k>n) return 0;
    int ans=fact[n];ans*=invf[k];ans%=p;ans*=invf[n-k];ans%=p;return ans;
}
const int sq=700;
vector<pair<int,int> > h[maxn/sq];
int res[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    fact[0]=1;for(int i=1;i<maxn;++i) {fact[i]=(fact[i-1]*i)%p;}
    for(int i=0;i<maxn;++i) {invf[i]=inv(fact[i]);}
    vector<pair<int,int> > que;
    int t;cin>>t;
    for(int cyc=0;cyc<t;++cyc)
    {
        int n,m;cin>>n>>m;
        h[(n+sq-1)/sq].push_back({m,cyc});
        que.push_back({n,m});
    }
    for(int i=1;i<=200005/sq+1;++i)
    {
        sort(h[i].begin(),h[i].end());
        int cur=0;int x=0;
        int r=0;
        while(cur!=h[i].size())
        {
            while(x!=h[i][cur].first)
            {
                r+=c(2*x,i*sq-1);r%=p;
                ++x;
            }
            res[h[i][cur].second]=r;
            ++cur;
        }
    }
    for(int i=0;i<que.size();++i)
    {
        auto [n,m]=que[i];
        int n1=((n+sq-1)/sq)*sq;
        int r=res[i];
        while(n1>n)
        {
            r=(-2*r+(c(2*m,n1)));r%=p;
            --n1;
        }
        cout<<(r%p+p)%p<<'\n';
    }
    return 0;
}
0