結果

問題 No.2703 FizzBuzz Letter Counting
ユーザー Magentor
提出日時 2024-03-15 01:03:48
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 3,856 bytes
コンパイル時間 5,921 ms
コンパイル使用メモリ 311,560 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-30 15:15:30
合計ジャッジ時間 86,135 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55 WA * 4 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
template<typename T> inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); }
template<typename T> inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); }
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep2(i, m ,n) for (int i = (m); i < (long long)(n); i++)
#define REP(i, n) for (long long i = 1; i < (long long)(n); i++)
typedef long long ll;
#define updiv(N,X) (N + X - 1) / X
#define l(n) n.begin(),n.end()
#define YesNo(Q) Q==1?cout<<"Yes":cout<<"No"
using P = pair<int, int>;
using mint = modint;
const int MOD = 998244353LL;
const ll INF = 999999999999LL;
vector<long long> fact, fact_inv, inv;
/* init_nCk :
:O(n)
*/
template <typename T>
void input(vector<T> &v){
rep(i,v.size()){cin>>v[i];}
return;
}
void init_nCk(int SIZE) {
fact.resize(SIZE + 5);
fact_inv.resize(SIZE + 5);
inv.resize(SIZE + 5);
fact[0] = fact[1] = 1;
fact_inv[0] = fact_inv[1] = 1;
inv[1] = 1;
for (int i = 2; i < SIZE + 5; i++) {
fact[i] = fact[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
fact_inv[i] = fact_inv[i - 1] * inv[i] % MOD;
}
}
/* nCk :MOD( int_nCk )
:O(1)
*/
long long nCk(int n, int k) {
assert(!(n < k));
assert(!(n < 0 || k < 0));
return fact[n] * (fact_inv[k] * fact_inv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll POW(ll a,ll n){
long long res = 1;
while (n > 0) {
if (n & 1) res = res * a;
a = a * a;
n >>= 1;
}
return res;
}
ll rp(ll a,ll m){
if(a==1){return 1;}
else if(a%2==1){return (rp(a-1,m)*10+1)%m;}
else{return (rp(a/2,m)*(modpow(10LL,a/2,m)+1))%m;}
}
inline long long mod(long long a, long long m) {
return (a % m + m) % m;
}
long long extGcd(long long a, long long b, long long &p, long long &q) {
if (b == 0) { p = 1; q = 0; return a; }
long long d = extGcd(b, a%b, q, p);
q -= a/b * p;
return d;
}
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
long long p, q;
long long d = extGcd(m1, m2, p, q);
if ((b2 - b1) % d != 0) return make_pair(0, -1);
long long m = m1 * (m2/d);
long long tmp = (b2 - b1) / d * p % (m2/d);
long long r = mod(b1 + m1 * tmp, m);
return make_pair(r, m);
}
int main() {
int n;cin>>n;
vector<ll> v(n);vector<ll> w(n);
ll sm = 0;
rep(i,n){cin>>v[i]>>w[i];sm += w[i];}
if(1==sm){cout<<w[0]+(w[0]/3+w[0]/5)*3<<endl;return 0;}
mint ans = 0;
ans += modpow(10LL,sm-1,998244353LL);
ans *= (9*(sm-1)+35);
ans -= 440;
ans *= 8;ans /= 135;
ans += 21;
// cout << ans.val() << endl;
ll md15 = 0; ll md998 = 0;
ll sm2 = sm;
rep(i,n){
sm2 -= w[i];
md15 += (modpow(10LL,sm2,15LL)*rp(w[i],15)*v[i]);md15 %= 15;
md998 += (modpow(10LL,sm2,998244353LL)*rp(w[i],998244353LL)*v[i]);md998 %= 998244353LL;
}
md15 += 1-modpow(10LL,sm-1,15LL);
//cout << 1-modpow(10LL,sm,15LL) << endl;
md15 = (md15%15+15)%15;
md998 += 1-modpow(10LL,sm-1,998244353LL);
//cout << md998 << endl;
md998 = (md998%998244353LL+998244353LL)%998244353LL;
// cout << sm << endl;
rep(i,md15){
if((i+modpow(10LL,sm-1,15LL))%3==0){ans += 4-sm;}
if((i+modpow(10LL,sm-1,15LL))%5==0){ans += 4-sm;}
if((i+modpow(10LL,sm-1,15LL))%15==0){ans += sm;}
ans += sm;
}
//cout << ans.val() << endl;
// cout << md998 << endl;
ll t = ChineseRem(md15,15LL,md998,998244353LL).first;
ans += ((8*sm+32)%998244353LL)*(t/15);
cout << ans.val() << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0