結果

問題 No.1711 Divide LCM
ユーザー chocoruskchocorusk
提出日時 2021-08-14 02:04:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,486 ms / 4,000 ms
コード長 2,886 bytes
コンパイル時間 4,033 ms
コンパイル使用メモリ 203,552 KB
実行使用メモリ 52,792 KB
最終ジャッジ日時 2023-10-17 19:50:40
合計ジャッジ時間 17,761 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
11,976 KB
testcase_01 AC 5 ms
11,976 KB
testcase_02 AC 5 ms
11,868 KB
testcase_03 AC 6 ms
12,020 KB
testcase_04 AC 12 ms
12,208 KB
testcase_05 AC 40 ms
12,672 KB
testcase_06 AC 14 ms
12,200 KB
testcase_07 AC 29 ms
12,588 KB
testcase_08 AC 15 ms
12,312 KB
testcase_09 AC 79 ms
13,336 KB
testcase_10 AC 19 ms
12,216 KB
testcase_11 AC 123 ms
13,676 KB
testcase_12 AC 19 ms
12,220 KB
testcase_13 AC 5 ms
12,004 KB
testcase_14 AC 8 ms
12,104 KB
testcase_15 AC 11 ms
12,152 KB
testcase_16 AC 5 ms
12,004 KB
testcase_17 AC 9 ms
12,104 KB
testcase_18 AC 118 ms
18,388 KB
testcase_19 AC 119 ms
18,384 KB
testcase_20 AC 118 ms
18,368 KB
testcase_21 AC 177 ms
20,416 KB
testcase_22 AC 2,486 ms
39,736 KB
testcase_23 AC 1,996 ms
52,792 KB
testcase_24 AC 205 ms
17,880 KB
testcase_25 AC 199 ms
17,684 KB
testcase_26 AC 192 ms
17,376 KB
testcase_27 AC 189 ms
17,764 KB
testcase_28 AC 180 ms
17,448 KB
testcase_29 AC 7 ms
12,036 KB
testcase_30 AC 206 ms
20,616 KB
testcase_31 AC 7 ms
12,036 KB
testcase_32 AC 178 ms
20,436 KB
testcase_33 AC 181 ms
20,424 KB
testcase_34 AC 14 ms
12,212 KB
testcase_35 AC 253 ms
18,080 KB
testcase_36 AC 281 ms
18,520 KB
testcase_37 AC 289 ms
18,528 KB
testcase_38 AC 118 ms
20,264 KB
testcase_39 AC 188 ms
21,396 KB
testcase_40 AC 6 ms
11,928 KB
testcase_41 AC 6 ms
11,928 KB
testcase_42 AC 7 ms
11,936 KB
testcase_43 AC 7 ms
11,936 KB
testcase_44 AC 7 ms
11,952 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:120:23: warning: narrowing conversion of 'x1' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
  120 |             que.push({x1, {c+1, j}});
      |                       ^~

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin>>n;
    int a[100010];
    vector<P> f[100010];
    int mx[1000010]={}, p1[1000010];
    vector<int> w;
    map<int, int> mp;
    auto dfs=[&](auto dfs, int x, int k, int c, vector<P> &v)->void{
        if(k==v.size()){
            if(c>1) mp[x]++;
            return;
        }
        auto q=v[k];
        dfs(dfs, x, k+1, c, v);
        if(mx[q.first]!=q.second){
            return;
        }
        dfs(dfs, x*p1[q.first], k+1, c+1, v);
    };
    for(int i=0; i<n; i++){
        int m; cin>>m;
        a[i]=1;
        for(int j=0; j<m; j++){
            int p, e;
            cin>>p>>e;
            for(int j=0; j<e; j++) a[i]*=p;
            f[i].push_back({p, e});
            mx[p]=max(mx[p], e);
        }
    }
    for(int i=2; i<=1000000; i++){
        if(mx[i]==0) continue;
        p1[i]=1;
        for(int j=0; j<mx[i]; j++) p1[i]*=i;
        w.push_back(p1[i]);
    }
    for(int i=0; i<n; i++){
        if(f[i].size()<w.size()) continue;
        bool ok=1;
        for(auto q:f[i]){
            if(mx[q.first]!=q.second){
                ok=0; break;
            }
        }
        if(ok){
            cout<<-1<<endl;
            return 0;
        }
    }
    for(int i=0; i<n; i++){
        dfs(dfs, 1, 0, 0, f[i]);
    }
    queue<pair<int, pair<int, int>>> que;
    for(int i=0; i<w.size(); i++){
        que.push({w[i], {1, i}});
    }
    auto ans=[&](ll x, int c){
        cout<<c<<endl;
        bool used[100010]={};
        for(auto q:w){
            if(x%q!=0) continue;
            vector<int> v;
            for(int i=0; i<n; i++){
                if(used[i]) continue;
                if(a[i]%q!=0){
                    v.push_back(i);
                    used[i]=1;
                }
            }
            cout<<v.size();
            for(auto i:v){
                cout<<" "<<a[i];
            }
            cout<<endl;
        }
    };
    while(!que.empty()){
        auto r=que.front(); que.pop();
        ll x=r.first;
        int c=r.second.first, i=r.second.second;
        for(int j=i+1; j<w.size(); j++){
            ll x1=x*w[j];
            if(mp.find(x1)==mp.end()){
                ans(x1, c+1);
                return 0;
            }
            que.push({x1, {c+1, j}});
        }
    }
    return 0;
}
0