結果

問題 No.2345 max(l,r)
ユーザー maksimmaksim
提出日時 2023-06-09 21:48:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,723 bytes
コンパイル時間 1,902 ms
コンパイル使用メモリ 180,756 KB
実行使用メモリ 18,172 KB
最終ジャッジ日時 2023-08-30 13:09:10
合計ジャッジ時間 15,597 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 135 ms
9,668 KB
testcase_01 AC 161 ms
9,604 KB
testcase_02 AC 155 ms
9,864 KB
testcase_03 AC 156 ms
9,628 KB
testcase_04 AC 156 ms
9,624 KB
testcase_05 AC 155 ms
9,672 KB
testcase_06 AC 156 ms
9,608 KB
testcase_07 AC 153 ms
9,696 KB
testcase_08 AC 156 ms
9,676 KB
testcase_09 AC 155 ms
9,588 KB
testcase_10 AC 152 ms
9,564 KB
testcase_11 AC 157 ms
9,760 KB
testcase_12 AC 155 ms
9,628 KB
testcase_13 AC 155 ms
9,616 KB
testcase_14 AC 155 ms
9,560 KB
testcase_15 AC 156 ms
9,616 KB
testcase_16 AC 157 ms
9,564 KB
testcase_17 AC 157 ms
9,564 KB
testcase_18 AC 156 ms
9,584 KB
testcase_19 AC 154 ms
9,676 KB
testcase_20 AC 157 ms
9,612 KB
testcase_21 AC 156 ms
9,564 KB
testcase_22 AC 212 ms
17,980 KB
testcase_23 AC 216 ms
18,172 KB
testcase_24 AC 152 ms
12,068 KB
testcase_25 AC 159 ms
9,712 KB
testcase_26 AC 159 ms
9,716 KB
testcase_27 AC 155 ms
9,736 KB
testcase_28 AC 143 ms
10,432 KB
testcase_29 AC 148 ms
10,724 KB
testcase_30 AC 139 ms
9,944 KB
testcase_31 AC 154 ms
11,016 KB
testcase_32 AC 143 ms
10,256 KB
testcase_33 AC 147 ms
10,468 KB
testcase_34 AC 135 ms
9,740 KB
testcase_35 AC 137 ms
9,976 KB
testcase_36 AC 140 ms
10,000 KB
testcase_37 AC 143 ms
10,272 KB
testcase_38 AC 161 ms
11,156 KB
testcase_39 WA -
testcase_40 AC 172 ms
11,332 KB
testcase_41 AC 158 ms
11,160 KB
testcase_42 AC 165 ms
11,304 KB
testcase_43 AC 163 ms
11,140 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 169 ms
11,408 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
testcase_61 WA -
testcase_62 WA -
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
testcase_66 WA -
testcase_67 WA -
testcase_68 AC 204 ms
9,672 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);
                l=h/2;r=h/2;
            }
        }
        res*=c1(m,tot);res%=p;
        cout<<(res%p+p)%p<<'\n';
    }
    return 0;
}
0