結果
| 問題 |
No.2345 max(l,r)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-09 21:48:33 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,723 bytes |
| コンパイル時間 | 1,846 ms |
| コンパイル使用メモリ | 176,300 KB |
| 実行使用メモリ | 18,332 KB |
| 最終ジャッジ日時 | 2025-01-02 02:47:39 |
| 合計ジャッジ時間 | 14,323 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 44 WA * 24 |
コンパイルメッセージ
main.cpp: In function ‘int32_t main()’:
main.cpp:24:43: warning: 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: warning: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
28 | for(auto [ma,c]:v)
| ^
ソースコード
#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;
}