結果

問題 No.1763 Many Balls
ユーザー chineristACchineristAC
提出日時 2021-11-20 15:12:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 679 ms / 10,000 ms
コード長 2,875 bytes
コンパイル時間 5,343 ms
コンパイル使用メモリ 220,772 KB
実行使用メモリ 12,608 KB
最終ジャッジ日時 2023-09-02 09:37:55
合計ジャッジ時間 46,943 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
12,268 KB
testcase_01 AC 162 ms
12,272 KB
testcase_02 AC 383 ms
12,264 KB
testcase_03 AC 8 ms
6,740 KB
testcase_04 AC 377 ms
12,276 KB
testcase_05 AC 380 ms
12,276 KB
testcase_06 AC 677 ms
12,296 KB
testcase_07 AC 605 ms
12,296 KB
testcase_08 AC 307 ms
12,332 KB
testcase_09 AC 531 ms
12,364 KB
testcase_10 AC 675 ms
12,276 KB
testcase_11 AC 14 ms
6,956 KB
testcase_12 AC 91 ms
12,296 KB
testcase_13 AC 166 ms
12,264 KB
testcase_14 AC 238 ms
12,332 KB
testcase_15 AC 453 ms
12,272 KB
testcase_16 AC 676 ms
12,292 KB
testcase_17 AC 676 ms
12,412 KB
testcase_18 AC 677 ms
12,260 KB
testcase_19 AC 677 ms
12,332 KB
testcase_20 AC 679 ms
12,360 KB
testcase_21 AC 678 ms
12,328 KB
testcase_22 AC 674 ms
12,292 KB
testcase_23 AC 678 ms
12,348 KB
testcase_24 AC 679 ms
12,296 KB
testcase_25 AC 678 ms
12,284 KB
testcase_26 AC 676 ms
12,428 KB
testcase_27 AC 673 ms
12,476 KB
testcase_28 AC 672 ms
12,336 KB
testcase_29 AC 676 ms
12,524 KB
testcase_30 AC 672 ms
12,444 KB
testcase_31 AC 673 ms
12,452 KB
testcase_32 AC 674 ms
12,536 KB
testcase_33 AC 679 ms
12,608 KB
testcase_34 AC 673 ms
12,396 KB
testcase_35 AC 675 ms
12,348 KB
testcase_36 AC 678 ms
12,544 KB
testcase_37 AC 667 ms
12,556 KB
testcase_38 AC 673 ms
12,480 KB
testcase_39 AC 673 ms
12,320 KB
testcase_40 AC 670 ms
12,400 KB
testcase_41 AC 677 ms
12,316 KB
testcase_42 AC 676 ms
12,568 KB
testcase_43 AC 677 ms
12,496 KB
testcase_44 AC 672 ms
12,408 KB
testcase_45 AC 676 ms
12,512 KB
testcase_46 AC 674 ms
12,476 KB
testcase_47 AC 678 ms
12,476 KB
testcase_48 AC 678 ms
12,556 KB
testcase_49 AC 675 ms
12,528 KB
testcase_50 AC 676 ms
12,528 KB
testcase_51 AC 679 ms
12,484 KB
testcase_52 AC 673 ms
12,480 KB
testcase_53 AC 668 ms
12,540 KB
testcase_54 AC 670 ms
12,496 KB
testcase_55 AC 670 ms
12,512 KB
testcase_56 AC 673 ms
12,476 KB
testcase_57 AC 670 ms
12,532 KB
testcase_58 AC 666 ms
12,472 KB
testcase_59 AC 675 ms
12,496 KB
testcase_60 AC 672 ms
12,528 KB
testcase_61 AC 678 ms
12,464 KB
testcase_62 AC 673 ms
12,524 KB
testcase_63 AC 678 ms
12,484 KB
testcase_64 AC 679 ms
12,532 KB
testcase_65 AC 679 ms
12,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <unordered_map>
#include <atcoder/all>
using namespace std;
using namespace atcoder;

//using mint = modint998244353;
#define rep(i,n) for (int i=0;i<n;i+=1)
#define rrep(i,n) for (int i=n-1;i>-1;i--)
#define append push_back
#define all(x) (x).begin(), (x).end()

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<endl;
}

ll lpow(int n,int k,int m){
  ll res = 1;
  ll e = n;
  while (k){
    if (k&1){
      res *= e;
      res %= m;
    }
    e = e * e;
    e %= m;
    k >>= 1;
  }
  return res;
}

const int mod = 90001;
const int r = 13;

const int r_60 = lpow(r,1500,mod);


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

  string N;
  int M;
  cin>>N>>M;
  vec<ll> exp = {1};

  int k;
  rep(i,M){
    vec<ll> exp_f(90001);
    cin>>k;
    vec<int> A(k);
    rep(j,k){
      cin>>A[j];
    }

    rep(bit,(1<<k)){
      int cnt = 0;
      int L = 1;
      rep(j,k){
        if ((bit>>j) & 1){
          cnt += 1;
          L = lcm(L,A[j]);
        }
      }
      if (cnt==0){
        continue;
      }
      ll inv = lpow(L,mod-2,mod);
      int a = lpow(r_60,60/L,mod);
      if (cnt&1){
        rep(j,L){
          exp_f[lpow(a,j,mod)] += inv;
          exp_f[lpow(a,j,mod)] %= mod;
        }
      }
      else{
        rep(j,L){
          exp_f[lpow(a,j,mod)] -= inv;
          if (exp_f[lpow(a,j,mod)] < 0){
            exp_f[lpow(a,j,mod)] += mod;
          }
          exp_f[lpow(a,j,mod)] %= mod;
        }
      }
    }
    
    exp = convolution_ll(exp,exp_f);
    for (int j=mod;j<exp.size();j++){
      exp[j%mod] += exp[j];
      exp[j%mod] %= mod;
    }
    exp.resize(mod);
    for (int j=0;j<mod;j++){
      exp[j] %= mod;
    }
  }

  int residu = 0;
  rep(i,N.size()){
    int a = N[i]-'0';
    residu = 10 * residu + a;
    residu %= 90000;
  }

  if (residu==0){
    residu = 90000;
  }

  ll res = 0;
  for (int a=0;a<mod;a++){
    res += exp[a] * lpow(a+1,residu,mod);
    res %= mod;
  }

  cout<<res<<endl;
}
0