結果

問題 No.1855 Intersected Lines
ユーザー 蜜蜂蜜蜂
提出日時 2022-01-09 22:31:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 2,562 bytes
コンパイル時間 3,849 ms
コンパイル使用メモリ 231,432 KB
実行使用メモリ 9,360 KB
最終ジャッジ日時 2023-09-14 13:56:12
合計ジャッジ時間 8,801 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 58 ms
9,136 KB
testcase_09 AC 65 ms
9,268 KB
testcase_10 AC 59 ms
9,284 KB
testcase_11 AC 71 ms
9,304 KB
testcase_12 AC 53 ms
9,160 KB
testcase_13 AC 102 ms
9,328 KB
testcase_14 AC 57 ms
9,196 KB
testcase_15 AC 82 ms
9,236 KB
testcase_16 AC 67 ms
9,192 KB
testcase_17 AC 82 ms
9,144 KB
testcase_18 AC 79 ms
9,180 KB
testcase_19 AC 79 ms
9,156 KB
testcase_20 AC 79 ms
9,360 KB
testcase_21 AC 80 ms
9,216 KB
testcase_22 AC 80 ms
9,248 KB
testcase_23 AC 63 ms
9,216 KB
testcase_24 AC 75 ms
9,300 KB
testcase_25 AC 62 ms
9,240 KB
testcase_26 AC 74 ms
9,252 KB
testcase_27 AC 74 ms
9,156 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:100:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  100 |     auto [ch,va]=s[i];
      |          ^
main.cpp:105:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  105 |         auto [c,v]=s[j];
      |              ^
main.cpp:123:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  123 |     auto [ch,va]=s[i];
      |          ^
main.cpp:128:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
  128 |         auto [c,v]=s[j];
      |              ^

ソースコード

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>;
using vst = vector<string>;
using vvst = vector<vst>;

#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--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

using mint = modint998244353;
constexpr ll mod = 998244353;

// xC4
mint c4(ll x){
  mint res=1;
  rep(i,0,4){
    res*=x-i;
    res/=i+1;
  }
  return res;
}

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

  ll n;
  int x;
  cin>>n>>x;

  mint ans=0;

  ll r=0,b=0;

  vector<pair<char,ll>> s(x);
  rep(i,0,x){
    char c;
    ll v;
    cin>>c>>v;
    s[i]={c,v};

    if(c=='R')r+=v;
    if(c=='B')b+=v;
  }

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

  /*
  (r-1)!! * (b-1)!! 通り

  赤同士の寄与
  2つ選ぶ rC4 通り
  他の決め方 (r-5)!! * (b-1)!! 通り

  期待値への寄与 rC4 * (r-5)!!/(r-1)!! = rC4 * 1/(r-1)(r-3)
  */

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

  rr=c4(r),bb=c4(b);
  rr/=(r-1)*(r-3);bb/=(b-1)*(b-3);

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

  /*
  ある赤線と青線を決め打った時 (r-3)!! * (b-3)!! 通り

  この2本がある確率 (r-3)!! / (r-1)!! * (b-3)!! / (b-1)!! = 1/(r-1)(b-1)
  */

  // sum1 pq sum2 p-q
  mint sum1=0,sum2=0;
  rep(i,0,x){
    auto [ch,va]=s[i];

    if(ch=='R'){
      mint p=0;
      rep(j,i,x){
        auto [c,v]=s[j];
        if(c=='R'){
          mint q=b-p;
          sum1+=p*q*v;
          sum2+=(p-q)*v;
        }
        else{
          p+=v;
        }
      }
      break;
    }
  }
  //rb+=sum1;

  mint rv=r;

  rep(i,0,x){
    auto [ch,va]=s[i];

    if(ch=='R'){
      mint p=0;
      rep(j,i,x){
        auto [c,v]=s[j];
        if(c=='R'){
          mint q=b-p;
          rb+=(sum1+sum2*p-p*p*rv)*v;
          sum1-=p*q*v;
          sum2-=(p-q)*v;
          rv-=v;
          //cout<<rb.val()<<" "<<p.val()<<endl;
        }
        else{
          p+=v;
        }
      }
      break;
    }
  }
  //rb/=2;
  rb/=(r-1)*(b-1);

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