結果

問題 No.1763 Many Balls
ユーザー chineristACchineristAC
提出日時 2021-11-20 15:05:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,832 bytes
コンパイル時間 7,151 ms
コンパイル使用メモリ 220,152 KB
実行使用メモリ 12,704 KB
最終ジャッジ日時 2023-09-02 09:29:38
合計ジャッジ時間 48,326 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
12,276 KB
testcase_01 AC 161 ms
12,216 KB
testcase_02 AC 380 ms
12,220 KB
testcase_03 AC 9 ms
6,728 KB
testcase_04 AC 377 ms
12,220 KB
testcase_05 AC 378 ms
12,332 KB
testcase_06 AC 669 ms
12,276 KB
testcase_07 AC 593 ms
12,276 KB
testcase_08 AC 309 ms
12,280 KB
testcase_09 AC 526 ms
12,328 KB
testcase_10 AC 674 ms
12,216 KB
testcase_11 AC 14 ms
6,668 KB
testcase_12 AC 93 ms
12,224 KB
testcase_13 AC 167 ms
12,300 KB
testcase_14 AC 238 ms
12,392 KB
testcase_15 AC 454 ms
12,324 KB
testcase_16 AC 670 ms
12,224 KB
testcase_17 AC 663 ms
12,328 KB
testcase_18 AC 662 ms
12,216 KB
testcase_19 AC 666 ms
12,336 KB
testcase_20 AC 669 ms
12,284 KB
testcase_21 AC 677 ms
12,284 KB
testcase_22 AC 673 ms
12,332 KB
testcase_23 AC 668 ms
12,468 KB
testcase_24 AC 674 ms
12,276 KB
testcase_25 AC 672 ms
12,292 KB
testcase_26 AC 679 ms
12,360 KB
testcase_27 AC 680 ms
12,364 KB
testcase_28 AC 674 ms
12,400 KB
testcase_29 AC 675 ms
12,500 KB
testcase_30 AC 676 ms
12,452 KB
testcase_31 AC 673 ms
12,392 KB
testcase_32 AC 662 ms
12,544 KB
testcase_33 AC 674 ms
12,576 KB
testcase_34 AC 672 ms
12,476 KB
testcase_35 AC 674 ms
12,388 KB
testcase_36 AC 680 ms
12,496 KB
testcase_37 AC 677 ms
12,492 KB
testcase_38 AC 679 ms
12,472 KB
testcase_39 AC 677 ms
12,356 KB
testcase_40 AC 677 ms
12,360 KB
testcase_41 AC 677 ms
12,312 KB
testcase_42 AC 678 ms
12,464 KB
testcase_43 AC 678 ms
12,452 KB
testcase_44 AC 680 ms
12,412 KB
testcase_45 AC 679 ms
12,568 KB
testcase_46 AC 676 ms
12,536 KB
testcase_47 AC 676 ms
12,532 KB
testcase_48 AC 672 ms
12,400 KB
testcase_49 AC 672 ms
12,476 KB
testcase_50 AC 673 ms
12,420 KB
testcase_51 AC 676 ms
12,424 KB
testcase_52 AC 670 ms
12,420 KB
testcase_53 AC 663 ms
12,484 KB
testcase_54 AC 673 ms
12,424 KB
testcase_55 AC 671 ms
12,476 KB
testcase_56 AC 665 ms
12,500 KB
testcase_57 WA -
testcase_58 AC 665 ms
12,528 KB
testcase_59 WA -
testcase_60 AC 670 ms
12,492 KB
testcase_61 WA -
testcase_62 AC 673 ms
12,492 KB
testcase_63 WA -
testcase_64 WA -
testcase_65 WA -
権限があれば一括ダウンロードができます

ソースコード

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;
  }

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

  cout<<res<<endl;
}
0