結果

問題 No.1855 Intersected Lines
ユーザー 蜜蜂蜜蜂
提出日時 2021-05-05 11:10:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,722 bytes
コンパイル時間 3,842 ms
コンパイル使用メモリ 231,184 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-14 03:45:00
合計ジャッジ時間 9,110 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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,376 KB
testcase_30 WA -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 5.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);

  mint rr=0,bb=0,rb=0;

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

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

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

  rep(i,0,2*n){
    rep(j,i+1,2*n){
      rep(k,j+1,2*n){
        rep(l,k+1,2*n){
          int r2=0;

          if(s[i]=='R')r2++;
          if(s[j]=='R')r2++;
          if(s[k]=='R')r2++;
          if(s[l]=='R')r2++;

          if(r2%2==1)continue;

          if(r2==2){
            if(s[i]==s[j])continue;
            if(s[j]==s[k])continue;
            if(s[k]==s[l])continue;
            if(s[l]==s[i])continue;

            rb+=fac(r-3)*fac(b-3);
          }
          else if(r2==4){
            rr+=fac(r-5)*fac(b-1);
          }
          else{
            bb+=fac(r-1)*fac(b-5);
          }

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