結果

問題 No.2356 Back Door Tour in Four Seasons
ユーザー planesplanes
提出日時 2023-06-17 12:58:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,391 bytes
コンパイル時間 1,726 ms
コンパイル使用メモリ 172,604 KB
実行使用メモリ 8,964 KB
最終ジャッジ日時 2023-09-07 09:44:58
合計ジャッジ時間 6,540 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
5,412 KB
testcase_01 AC 34 ms
5,420 KB
testcase_02 AC 34 ms
5,476 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 33 ms
5,416 KB
testcase_06 AC 34 ms
5,352 KB
testcase_07 AC 34 ms
5,368 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 34 ms
5,612 KB
testcase_29 AC 34 ms
5,488 KB
testcase_30 AC 71 ms
8,444 KB
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

  #include <bits/stdc++.h> 
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 #define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

ll INF=2e18;

const int mod=998244353;

class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

mint mod_pow(ll x,ll n,ll mod) {
mint res=1;
  while(n>0) {
if(n&1) {
res=res*x;
}
   x=x*x%mod;
    n>>=1;
  }
return res;
}
 

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

ll N;cin>>N;
vector<vector<ll>> vec(4,vector<ll> (0));
for(ll i=0;i<N;i++) {
  char c;cin>>c;
  ll a;cin>>a;
  if(c=='U') vec[0].push_back(a);
  else if(c=='F') vec[1].push_back(a);
  else if(c=='W') vec[2].push_back(a);
  else vec[3].push_back(a);
}

vector<mint> note(300000+100);
note[1]=1;
for(ll i=2;i<300000+100;i++) {
  note[i]=note[i-1]*(N-1);
  note[i]+=mod_pow(N-2,i-1,mod);
  }



mint next=0;
ll s=0;
for(auto x:vec[3]) s+=x;

next=mod_pow(N-1,s,mod);



for(ll i=2;i>=0;i--) {
  vector<mint> dp(vec[i].size());
  ll s=0;
for(auto x:vec[i]) s+=x;

for(ll j=0;j<dp.size();j++) {
  ll a=vec[i][j];
  dp[j]+=next*note[a]*mod_pow(N-1,s-a,mod);
}

next=0;
for(auto x:dp) {
  next+=x;
}
}

cout<<next<<endl;
}


0