結果

問題 No.2703 FizzBuzz Letter Counting
ユーザー MagentorMagentor
提出日時 2024-03-17 12:24:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 3,000 ms
コード長 3,962 bytes
コンパイル時間 5,261 ms
コンパイル使用メモリ 312,500 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-29 20:35:43
合計ジャッジ時間 11,889 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 142 ms
6,548 KB
testcase_04 AC 21 ms
6,548 KB
testcase_05 AC 22 ms
6,548 KB
testcase_06 AC 64 ms
6,548 KB
testcase_07 AC 111 ms
6,548 KB
testcase_08 AC 10 ms
6,548 KB
testcase_09 AC 125 ms
6,548 KB
testcase_10 AC 66 ms
6,548 KB
testcase_11 AC 8 ms
6,548 KB
testcase_12 AC 88 ms
6,548 KB
testcase_13 AC 32 ms
6,548 KB
testcase_14 AC 148 ms
6,548 KB
testcase_15 AC 142 ms
6,548 KB
testcase_16 AC 139 ms
6,548 KB
testcase_17 AC 17 ms
6,548 KB
testcase_18 AC 102 ms
6,548 KB
testcase_19 AC 82 ms
6,548 KB
testcase_20 AC 100 ms
6,548 KB
testcase_21 AC 60 ms
6,548 KB
testcase_22 AC 33 ms
6,548 KB
testcase_23 AC 155 ms
6,548 KB
testcase_24 AC 77 ms
6,548 KB
testcase_25 AC 84 ms
6,548 KB
testcase_26 AC 147 ms
6,548 KB
testcase_27 AC 128 ms
6,548 KB
testcase_28 AC 162 ms
6,548 KB
testcase_29 AC 163 ms
6,548 KB
testcase_30 AC 163 ms
6,548 KB
testcase_31 AC 162 ms
6,548 KB
testcase_32 AC 162 ms
6,548 KB
testcase_33 AC 163 ms
6,548 KB
testcase_34 AC 162 ms
6,548 KB
testcase_35 AC 164 ms
6,548 KB
testcase_36 AC 162 ms
6,548 KB
testcase_37 AC 162 ms
6,548 KB
testcase_38 AC 163 ms
6,548 KB
testcase_39 AC 162 ms
6,548 KB
testcase_40 AC 162 ms
6,548 KB
testcase_41 AC 162 ms
6,548 KB
testcase_42 AC 162 ms
6,548 KB
testcase_43 AC 2 ms
6,548 KB
testcase_44 AC 2 ms
6,548 KB
testcase_45 AC 1 ms
6,548 KB
testcase_46 AC 2 ms
6,548 KB
testcase_47 AC 2 ms
6,548 KB
testcase_48 AC 2 ms
6,548 KB
testcase_49 AC 1 ms
6,548 KB
testcase_50 AC 2 ms
6,548 KB
testcase_51 AC 2 ms
6,548 KB
testcase_52 AC 2 ms
6,548 KB
testcase_53 AC 2 ms
6,548 KB
testcase_54 AC 1 ms
6,548 KB
testcase_55 AC 2 ms
6,548 KB
testcase_56 AC 2 ms
6,548 KB
testcase_57 AC 2 ms
6,548 KB
testcase_58 AC 2 ms
6,548 KB
testcase_59 AC 2 ms
6,548 KB
testcase_60 AC 2 ms
6,548 KB
testcase_61 AC 2 ms
6,548 KB
testcase_62 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'll rp(ll, ll)':
main.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^

ソースコード

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(m==998244353){
	return ((modpow(10LL,a,998244353LL)-1)*modpow(9LL,998244351LL,998244353LL))%998244353LL;	
	}
	if(m==15){
	if(a==0){return 0;}
	else if(a%3==0){return 6;}
	else if(a%3==1){return 1;}
	else{return 11;}
	}

}
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<<v[0]+(v[0]/3+v[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;
}
0