結果

問題 No.1330 Multiply or Divide
ユーザー hiro71687khiro71687k
提出日時 2023-08-23 08:13:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,803 bytes
コンパイル時間 4,978 ms
コンパイル使用メモリ 272,572 KB
実行使用メモリ 72,856 KB
最終ジャッジ日時 2023-08-23 08:13:59
合計ジャッジ時間 20,431 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 31 ms
4,944 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 WA -
testcase_35 AC 100 ms
11,724 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 226 ms
18,700 KB
testcase_39 AC 141 ms
13,872 KB
testcase_40 AC 177 ms
16,172 KB
testcase_41 AC 79 ms
9,704 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ll inf=1009999999999999990;
int main(){
    ll n,m,p;
    cin >> n >> m >> p;
    vector<ll>a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll>b;
    map<ll,ll>mmm;
    for (ll i = 0; i < n; i++)
    {
        if (a[i]!=1&&mmm[a[i]]==0)
        {
            b.push_back(a[i]);
            mmm[a[i]]=1;
        }
    }
    n=b.size();
    a=b;
    map<ll,ll>memo;
    memo[1]=1;
    priority_queue<ll>pq;
    map<ll,ll>mm;
    pq.push(1);
    ll ans=32;
    ll now=0;
    while (!pq.empty())
    {
        now++;
        if (now>100000)
        {
            cout << -1 << endl;
            return 0;
        }
        
        ll v=pq.top();
        pq.pop();
        mm[v]=0;
        if (v>=m)
        {
            ans=min(ans,memo[v]);
        }
        if (ans<=memo[v])
        {
            continue;
        }
        if (v%p==0)
        {
            v/=p;
            ll x=memo[v];
            if (x==0||x>memo[v*p]+1)
            {
                memo[v]=memo[v*p]+1;
                if (mm[v]==0)
                {
                    pq.push(v);
                    mm[v]++;
                }
            }
            continue;
        }
        for (ll i = 0; i < n; i++)
        {
            ll x=memo[v*a[i]];
            if (x==0||x>memo[v]+1)
            {
                memo[v*a[i]]=memo[v]+1;
                if (mm[v*a[i]]==0)
                {
                    pq.push(v*a[i]);
                    mm[v*a[i]]++;
                }
            }
        }
    }
    if (ans==32)
    {
        cout << -1 << endl;
    }else{
        cout << ans-1 << endl;
    }
}
0