結果

問題 No.1711 Divide LCM
ユーザー chocoruskchocorusk
提出日時 2021-08-14 20:56:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 919 ms / 4,000 ms
コード長 3,783 bytes
コンパイル時間 9,143 ms
コンパイル使用メモリ 307,508 KB
実行使用メモリ 52,468 KB
最終ジャッジ日時 2023-10-17 19:53:08
合計ジャッジ時間 19,717 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
10,144 KB
testcase_01 AC 11 ms
10,144 KB
testcase_02 AC 11 ms
10,016 KB
testcase_03 AC 11 ms
10,212 KB
testcase_04 AC 15 ms
10,440 KB
testcase_05 AC 32 ms
11,012 KB
testcase_06 AC 17 ms
10,436 KB
testcase_07 AC 26 ms
10,916 KB
testcase_08 AC 17 ms
10,592 KB
testcase_09 AC 55 ms
11,800 KB
testcase_10 AC 20 ms
10,456 KB
testcase_11 AC 74 ms
12,188 KB
testcase_12 AC 21 ms
10,456 KB
testcase_13 AC 11 ms
10,180 KB
testcase_14 AC 13 ms
10,308 KB
testcase_15 AC 15 ms
10,364 KB
testcase_16 AC 11 ms
10,180 KB
testcase_17 AC 13 ms
10,308 KB
testcase_18 AC 102 ms
23,236 KB
testcase_19 AC 99 ms
23,248 KB
testcase_20 AC 97 ms
23,228 KB
testcase_21 AC 143 ms
23,752 KB
testcase_22 AC 919 ms
35,480 KB
testcase_23 AC 804 ms
52,468 KB
testcase_24 AC 111 ms
17,828 KB
testcase_25 AC 110 ms
17,564 KB
testcase_26 AC 107 ms
17,316 KB
testcase_27 AC 112 ms
18,044 KB
testcase_28 AC 112 ms
17,652 KB
testcase_29 AC 12 ms
10,224 KB
testcase_30 AC 129 ms
20,932 KB
testcase_31 AC 12 ms
10,220 KB
testcase_32 AC 142 ms
22,500 KB
testcase_33 AC 140 ms
22,500 KB
testcase_34 AC 16 ms
10,460 KB
testcase_35 AC 135 ms
17,580 KB
testcase_36 AC 144 ms
18,012 KB
testcase_37 AC 143 ms
18,008 KB
testcase_38 AC 128 ms
27,068 KB
testcase_39 AC 144 ms
24,016 KB
testcase_40 AC 11 ms
10,112 KB
testcase_41 AC 12 ms
10,108 KB
testcase_42 AC 11 ms
10,124 KB
testcase_43 AC 11 ms
10,128 KB
testcase_44 AC 12 ms
10,144 KB
権限があれば一括ダウンロードができます

ソースコード

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>
#include "testlib.h"
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
const int MAXN=100000;
const int MAXA=1000000000;
const int MAXP=1000000;
const int MAXM=200000;
bitset<MAXP+1> isprime;
void sieve(){
    for(int i=3; i<MAXP+1; i++, i++) isprime[i]=1;
    isprime[2]=1;
    for(int i=3; i<MAXP+1; i++){
        if(isprime[i]){
            for(int j=(i<<1); j<MAXP+1; j+=i) isprime[j]=0;
        }
    }
}
ll a[MAXN];
vector<P> f[MAXN];
int mx[MAXP], p1[MAXP];

int main(int argc, char* argv[]){
    registerValidation(argc, argv);
    sieve();
    int n=inf.readInt(1, MAXN);
    inf.readEoln();

    vector<int> w;
    unordered_map<int, int> mp;
    int ms=0;
    for(int i=0; i<n; i++){
        int m=inf.readInt(1, MAXM);
        inf.readEoln();
        ms+=m;

        a[i]=1;
        for(int j=0; j<m; j++){
            int p, e;
            p=inf.readInt(2, MAXP);
            ensure(isprime[p]);
            inf.readSpace();
            e=inf.readInt(1, 100);
            inf.readEoln();

            for(int j=0; j<e; j++){
                a[i]*=p;
                ensure(a[i]<=MAXA);
            }

            f[i].push_back({p, e});
            mx[p]=max(mx[p], e);
        }
    }
    ensure(ms<=MAXM);
    set<ll> sta;
    for(int i=0; i<n; i++) sta.insert(a[i]);
    ensure(sta.size()==n);
    inf.readEof();

    for(int i=2; i<MAXP; 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++){
        vector<int> f1;
        for(auto q:f[i]){
            if(mx[q.first]==q.second) f1.push_back(p1[q.first]);
        }
        int m=f1.size();
        for(int j=0; j<(1<<m); j++){
            int c=0, x=1;
            for(int k=0; k<m; k++){
                if(j&(1<<k)){
                    c++;
                    x*=f1[k];
                }
            }
            if(c>1) mp[x]++;
        }
    }
    queue<P> que;
    for(int i=0; i<w.size(); i++){
        que.push({w[i], i});
    }
    auto ans=[&](ll x){
        int c=0;
        for(auto q:w){
            if(x%q==0) 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 i=r.second;
        for(int j=i+1; j<w.size(); j++){
            ll x1=x*w[j];
            if(mp.find(x1)==mp.end()){
                ans(x1);
                return 0;
            }
            que.push({x1, j});
        }
    }
    return 0;
}
0