結果

問題 No.2742 Car Flow
ユーザー butsurizukibutsurizuki
提出日時 2024-04-21 03:40:09
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,905 bytes
コンパイル時間 3,415 ms
コンパイル使用メモリ 273,768 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2024-04-21 03:40:16
合計ジャッジ時間 5,960 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
19,968 KB
testcase_01 AC 27 ms
19,840 KB
testcase_02 AC 31 ms
19,840 KB
testcase_03 AC 28 ms
19,840 KB
testcase_04 AC 35 ms
19,840 KB
testcase_05 AC 27 ms
19,968 KB
testcase_06 AC 27 ms
19,840 KB
testcase_07 AC 27 ms
19,968 KB
testcase_08 AC 27 ms
19,840 KB
testcase_09 AC 28 ms
19,968 KB
testcase_10 AC 24 ms
19,840 KB
testcase_11 AC 25 ms
19,868 KB
testcase_12 AC 24 ms
19,968 KB
testcase_13 AC 22 ms
19,840 KB
testcase_14 AC 22 ms
19,968 KB
testcase_15 AC 17 ms
19,840 KB
testcase_16 AC 27 ms
19,896 KB
testcase_17 AC 28 ms
19,936 KB
testcase_18 AC 16 ms
19,940 KB
testcase_19 AC 28 ms
19,944 KB
testcase_20 AC 19 ms
19,948 KB
testcase_21 AC 18 ms
19,800 KB
testcase_22 AC 25 ms
19,888 KB
testcase_23 AC 26 ms
19,936 KB
testcase_24 AC 21 ms
19,840 KB
testcase_25 AC 26 ms
19,920 KB
testcase_26 AC 28 ms
19,968 KB
testcase_27 AC 19 ms
19,820 KB
testcase_28 AC 19 ms
19,840 KB
testcase_29 AC 16 ms
19,840 KB
testcase_30 AC 25 ms
19,968 KB
testcase_31 AC 18 ms
19,968 KB
testcase_32 AC 25 ms
19,712 KB
testcase_33 AC 24 ms
19,900 KB
testcase_34 AC 19 ms
19,844 KB
testcase_35 AC 18 ms
19,840 KB
testcase_36 AC 25 ms
19,856 KB
testcase_37 AC 19 ms
19,840 KB
testcase_38 AC 25 ms
19,816 KB
testcase_39 AC 17 ms
19,840 KB
testcase_40 AC 16 ms
19,840 KB
testcase_41 AC 15 ms
19,840 KB
testcase_42 AC 15 ms
19,880 KB
testcase_43 AC 15 ms
19,968 KB
testcase_44 AC 16 ms
19,840 KB
testcase_45 AC 15 ms
19,968 KB
testcase_46 AC 16 ms
19,840 KB
testcase_47 AC 15 ms
19,812 KB
testcase_48 AC 16 ms
19,968 KB
testcase_49 AC 15 ms
19,712 KB
testcase_50 AC 16 ms
19,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Counting Template
#include<bits/stdc++.h>

using namespace std;

#define mod 998244353
#define FACSIZE 1048576

long long power(long long a,long long b){
  long long x=1,y=a;
  while(b>0){
    if(b&1ll){
      x=(x*y)%mod;
    }
    y=(y*y)%mod;
    b>>=1;
  }
  return x%mod;
}

long long modular_inverse(long long n){
  return power(n,mod-2);
}

long long factorial[FACSIZE];
long long invfact[FACSIZE];

void cfact(){
  long long i;
  factorial[0]=1;
  factorial[1]=1;
  for(i=2;i<FACSIZE;i++){
    factorial[i]=factorial[i-1]*i;
    factorial[i]%=mod;
  }
  invfact[FACSIZE-1]=modular_inverse(factorial[FACSIZE-1]);
  for(i=FACSIZE-2;i>=0;i--){
    invfact[i]=invfact[i+1]*(i+1);
    invfact[i]%=mod;
  }
}

long long calcnCr(long long n,long long k){
  if(k<0 || n<k){return 0;}
  return (factorial[n]*((invfact[k]*invfact[n-k])%mod))%mod;
}

long long solve(){
  long long n;
  cin >> n;
  long long p=0,q=0;
  for(long long i=0;i<n;i++){
    long long a;
    cin >> a;
    p+=a;
    q++;
  }
  p=min(p,n-p);
  return (p*modular_inverse(q))%mod;
}

int main(){
  cfact();
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t=1;
  // cin >> t;
  while(t>0){
    t--;
    cout << solve()%mod << "\n";
  }
  return 0;
}

// #include<bits/stdc++.h>
//
// using namespace std;
//
// vector<int> f(vector<int> &a){
//   int n=a.size();
//   vector<int> res;
//   for(int i=0;i<n;i++){
//     if(a[(i+n-1)%n]==1 && a[i]==0){
//       res.push_back(1);
//       continue;
//     }
//     else if(a[i]==1 && a[(i+1)%n]==1){
//       res.push_back(1);
//       continue;
//     }
//     else{
//       res.push_back(0);
//     }
//   }
//   return res;
// }
//
// int main(){
//   ios::sync_with_stdio(false);
//   cin.tie(nullptr);
//   vector<int> a={1,1,0};
//   for(int tr=0;tr<10;tr++){
//     for(auto &nx : a){cout << nx << " ";}
//     cout << "\n";
//     a=f(a);
//   }
//   return 0;
// }
0