結果

問題 No.2345 max(l,r)
ユーザー maksimmaksim
提出日時 2023-06-09 21:49:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 1,730 bytes
コンパイル時間 1,777 ms
コンパイル使用メモリ 180,104 KB
実行使用メモリ 18,300 KB
最終ジャッジ日時 2023-08-30 13:09:42
合計ジャッジ時間 16,563 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 148 ms
9,744 KB
testcase_01 AC 174 ms
9,704 KB
testcase_02 AC 167 ms
9,608 KB
testcase_03 AC 164 ms
9,648 KB
testcase_04 AC 169 ms
9,672 KB
testcase_05 AC 169 ms
9,832 KB
testcase_06 AC 167 ms
9,888 KB
testcase_07 AC 166 ms
9,680 KB
testcase_08 AC 168 ms
9,604 KB
testcase_09 AC 168 ms
9,828 KB
testcase_10 AC 169 ms
9,660 KB
testcase_11 AC 170 ms
9,664 KB
testcase_12 AC 169 ms
9,632 KB
testcase_13 AC 168 ms
9,772 KB
testcase_14 AC 169 ms
9,832 KB
testcase_15 AC 168 ms
9,620 KB
testcase_16 AC 168 ms
9,648 KB
testcase_17 AC 169 ms
9,628 KB
testcase_18 AC 168 ms
9,676 KB
testcase_19 AC 169 ms
9,652 KB
testcase_20 AC 169 ms
9,648 KB
testcase_21 AC 167 ms
9,684 KB
testcase_22 AC 229 ms
18,124 KB
testcase_23 AC 234 ms
18,300 KB
testcase_24 AC 166 ms
11,940 KB
testcase_25 AC 170 ms
9,820 KB
testcase_26 AC 168 ms
9,800 KB
testcase_27 AC 166 ms
10,072 KB
testcase_28 AC 154 ms
10,516 KB
testcase_29 AC 163 ms
10,656 KB
testcase_30 AC 151 ms
9,968 KB
testcase_31 AC 170 ms
11,004 KB
testcase_32 AC 155 ms
10,196 KB
testcase_33 AC 160 ms
10,468 KB
testcase_34 AC 148 ms
9,672 KB
testcase_35 AC 148 ms
10,072 KB
testcase_36 AC 152 ms
10,020 KB
testcase_37 AC 155 ms
10,232 KB
testcase_38 AC 171 ms
11,184 KB
testcase_39 AC 192 ms
12,024 KB
testcase_40 AC 185 ms
11,412 KB
testcase_41 AC 174 ms
11,232 KB
testcase_42 AC 177 ms
11,304 KB
testcase_43 AC 174 ms
11,256 KB
testcase_44 AC 190 ms
11,784 KB
testcase_45 AC 218 ms
14,368 KB
testcase_46 AC 208 ms
13,292 KB
testcase_47 AC 180 ms
11,264 KB
testcase_48 AC 160 ms
9,692 KB
testcase_49 AC 160 ms
10,008 KB
testcase_50 AC 161 ms
9,764 KB
testcase_51 AC 160 ms
9,708 KB
testcase_52 AC 160 ms
9,720 KB
testcase_53 AC 159 ms
9,820 KB
testcase_54 AC 161 ms
9,844 KB
testcase_55 AC 158 ms
9,736 KB
testcase_56 AC 161 ms
9,848 KB
testcase_57 AC 159 ms
9,700 KB
testcase_58 AC 170 ms
9,784 KB
testcase_59 AC 173 ms
9,732 KB
testcase_60 AC 173 ms
9,772 KB
testcase_61 AC 173 ms
9,704 KB
testcase_62 AC 172 ms
9,720 KB
testcase_63 AC 176 ms
9,748 KB
testcase_64 AC 175 ms
9,740 KB
testcase_65 AC 172 ms
9,996 KB
testcase_66 AC 172 ms
9,716 KB
testcase_67 AC 173 ms
9,724 KB
testcase_68 AC 217 ms
9,764 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int32_t main()’ 内:
main.cpp:24:43: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   24 |         vector<pair<int,int> > v;for(auto [key,val]:u) v.push_back({key,val});
      |                                           ^
main.cpp:28:18: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   28 |         for(auto [ma,c]:v)
      |                  ^

ソースコード

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 c1(int n,int k)
{
    if(n<k || n<0 || k<0) return 0;
    int res=fact[n];res*=invf[k];res%=p;res*=invf[n-k];res%=p;return res;
}
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]);
    int t;cin>>t;
    while(t--)
    {
        int n,m;cin>>n>>m;int a[n];for(int i=0;i<n;++i) cin>>a[i];
        map<int,int> u;for(int i=0;i<n;++i) u[a[i]]++;
        vector<pair<int,int> > v;for(auto [key,val]:u) v.push_back({key,val});
        sort(v.begin(),v.end());reverse(v.begin(),v.end());
        int l=n,r=n;
        int res=1;int tot=0;int rem=v.size();
        for(auto [ma,c]:v)
        {
            --rem;
            if(ma==r-c && 2*(r-c)+c>=n)
            {
                ++tot;
                if(l==r && rem) {res*=2;res%=p;}
                r-=c;
            }
            else if(ma==l-c && 2*(l-c)+c>=n)
            {
                ++tot;
                l-=c;
            }
            else
            {
                int h=(l+r-c);
                if(h%2==1) {res*=0;res%=p;}
                if(h!=2*ma) {res*=0;res%=p;}
                tot+=2;
                int o=l-h/2;
                res*=c1(c,o);res%=p;
                l=h/2;r=h/2;
            }
        }
        res*=c1(m,tot);res%=p;
        cout<<(res%p+p)%p<<'\n';
    }
    return 0;
}
0