結果

問題 No.2578 Jewelry Store
ユーザー maksimmaksim
提出日時 2023-12-10 05:40:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,721 ms / 3,500 ms
コード長 2,017 bytes
コンパイル時間 2,261 ms
コンパイル使用メモリ 180,188 KB
実行使用メモリ 15,664 KB
最終ジャッジ日時 2023-12-10 05:40:54
合計ジャッジ時間 18,370 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 28 ms
6,676 KB
testcase_03 AC 23 ms
6,676 KB
testcase_04 AC 67 ms
6,676 KB
testcase_05 AC 22 ms
6,676 KB
testcase_06 AC 27 ms
6,676 KB
testcase_07 AC 40 ms
6,676 KB
testcase_08 AC 23 ms
6,676 KB
testcase_09 AC 45 ms
6,676 KB
testcase_10 AC 62 ms
6,676 KB
testcase_11 AC 22 ms
6,676 KB
testcase_12 AC 24 ms
6,676 KB
testcase_13 AC 23 ms
6,676 KB
testcase_14 AC 22 ms
6,676 KB
testcase_15 AC 22 ms
6,676 KB
testcase_16 AC 62 ms
6,676 KB
testcase_17 AC 41 ms
6,676 KB
testcase_18 AC 22 ms
6,676 KB
testcase_19 AC 31 ms
6,676 KB
testcase_20 AC 41 ms
6,676 KB
testcase_21 AC 41 ms
6,676 KB
testcase_22 AC 26 ms
6,676 KB
testcase_23 AC 18 ms
6,676 KB
testcase_24 AC 33 ms
6,676 KB
testcase_25 AC 13 ms
6,676 KB
testcase_26 AC 17 ms
6,676 KB
testcase_27 AC 191 ms
6,676 KB
testcase_28 AC 237 ms
6,676 KB
testcase_29 AC 241 ms
6,676 KB
testcase_30 AC 300 ms
6,676 KB
testcase_31 AC 160 ms
6,676 KB
testcase_32 AC 106 ms
10,752 KB
testcase_33 AC 124 ms
7,552 KB
testcase_34 AC 190 ms
9,088 KB
testcase_35 AC 45 ms
6,784 KB
testcase_36 AC 130 ms
11,392 KB
testcase_37 AC 109 ms
6,676 KB
testcase_38 AC 282 ms
6,676 KB
testcase_39 AC 133 ms
6,676 KB
testcase_40 AC 112 ms
6,676 KB
testcase_41 AC 150 ms
6,676 KB
testcase_42 AC 117 ms
6,676 KB
testcase_43 AC 141 ms
6,676 KB
testcase_44 AC 2,721 ms
6,676 KB
testcase_45 AC 575 ms
6,676 KB
testcase_46 AC 348 ms
6,676 KB
testcase_47 AC 463 ms
6,676 KB
testcase_48 AC 247 ms
15,664 KB
testcase_49 AC 980 ms
6,676 KB
testcase_50 AC 943 ms
6,676 KB
testcase_51 AC 1,990 ms
6,676 KB
testcase_52 AC 251 ms
6,676 KB
testcase_53 AC 58 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int32_t main()':
main.cpp:36:31: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   36 |     vector<int> prim;for(auto [p,val]:cnt) {int o=1;for(int i=0;i<val;++i) o*=p; prim.push_back(o);}
      |                               ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define app push_back
const int p=998244353;
vector<int> rasl(int n)
{
    vector<int> v;
    if(n==1) {return v;}
    if(n%2==0) {v=rasl(n/2);v.app(2);return v;}
    if(n%3==0) {v=rasl(n/3);v.app(3);return v;}
    for(int p=5;p*p<=n;p+=6)
    {
        if(n%p==0)
        {
            v=rasl(n/p);v.app(p);return v;
        }
    }
    for(int p=7;p*p<=n;p+=6)
    {
        if(n%p==0)
        {
            v=rasl(n/p);v.app(p);return v;
        }
    }
    v.app(n);return v;
}
int we[1<<16];
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t,m;cin>>t>>m;
    vector<int> v=rasl(m);
    map<int,int> cnt;for(int p:v) cnt[p]++;
    vector<int> prim;for(auto [p,val]:cnt) {int o=1;for(int i=0;i<val;++i) o*=p; prim.push_back(o);}
    int sz=prim.size();
    while(t--)
    {
        int n,b,c,d;cin>>n>>b>>c>>d;
        int a[n];for(int i=0;i<n;++i) {cin>>a[i];}
        int w[n]={b};for(int i=1;i<n;++i) {w[i]=(w[i-1]*c+d)%p;}
        for(int i=0;i<n;++i) {++w[i];w[i]%=p;}
        int msk[n];fill(we,we+(1<<16),1LL);
        for(int i=0;i<n;++i)
        {
            if(m%a[i]) {msk[i]=(-1);}
            else {
                msk[i]=0;
            for(int j=0;j<sz;++j) if(a[i]%prim[j]==0) msk[i]+=(1<<j);
            we[msk[i]]*=w[i];we[msk[i]]%=p;
            }
        }
        for(int i=0;i<sz;++i)
        {
            for(int mask=0;mask<(1<<sz);++mask)
            {
                if(!(mask & (1<<i)))
                {
                    we[mask+(1<<i)]*=we[mask];we[mask+(1<<i)]%=p;
                }
            }
        }
        int res=0;
        for(int mask=0;mask<(1<<sz);++mask)
        {
            if((__builtin_popcount(mask)+sz)%2==0)
            {
                res+=we[mask];res%=p;
            }
            else
            {
                res-=we[mask];res%=p;
            }
        }
        if(m==1) {--res;}
        cout<<(res%p+p)%p<<'\n';
    }
    return 0;
}
0