結果

問題 No.1855 Intersected Lines
ユーザー 蜜蜂蜜蜂
提出日時 2021-05-05 11:08:48
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,596 bytes
コンパイル時間 3,493 ms
コンパイル使用メモリ 229,448 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-09-14 03:44:26
合計ジャッジ時間 11,295 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 6.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)

using mint = modint998244353;

//n!!
mint fac(int n){
  if(n<=0){
    return 1;
  }
  mint res=1;
  return res*n*fac(n-2);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  string s;
  cin>>n>>s;

  int r=0,b=0;
  vi red;
  rep(i,0,2*n){
    if(s[i]=='R'){
      red.pb(b);
      r++;
    }
    else{
      b++;
    }
  }

  if(r%2==1){
    cout<<0<<endl;
    return 0;
  }

  mint rr=1,bb=1,rb=0,sum=0,sum2=0;

  rep(i,1,5){
    rr*=r-i+1;
    bb*=b-i+1;
    rr/=i,bb/=i;
  }
  rr*=fac(r-5)*fac(b-1);
  bb*=fac(r-1)*fac(b-5);

  if(r==0||b==0){
    rr+=bb;
    cout<<rr.val()<<endl;
    return 0;
  }

  rep(i,1,r){
    ll p,q;
    p=red[i]-red[0];
    q=b-p;
    sum+=p*q;
    sum2+=p-q;
  }
  rb+=sum;

  rep(i,1,r){
    ll p,q;
    p=red[i]-red[0];
    q=b-p;
    sum-=p*q;
    sum2-=p-q;
    ll c=red[i]-red[0];
    rb+=sum+sum2*c-c*c*(r-i-1);
  }
  rb*=fac(r-3)*fac(b-3);

  mint ans=rr+bb+rb;
  cout<<ans.val()<<endl;
}
0