結果

問題 No.1711 Divide LCM
ユーザー chocoruskchocorusk
提出日時 2021-08-14 02:19:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 939 ms / 4,000 ms
コード長 3,237 bytes
コンパイル時間 4,846 ms
コンパイル使用メモリ 201,060 KB
実行使用メモリ 48,404 KB
最終ジャッジ日時 2023-10-17 19:51:15
合計ジャッジ時間 14,025 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,216 KB
testcase_01 AC 4 ms
7,216 KB
testcase_02 AC 4 ms
7,104 KB
testcase_03 AC 6 ms
7,264 KB
testcase_04 AC 11 ms
7,440 KB
testcase_05 AC 32 ms
7,860 KB
testcase_06 AC 12 ms
7,436 KB
testcase_07 AC 25 ms
7,796 KB
testcase_08 AC 13 ms
7,552 KB
testcase_09 AC 60 ms
8,428 KB
testcase_10 AC 16 ms
7,448 KB
testcase_11 AC 81 ms
8,712 KB
testcase_12 AC 17 ms
7,448 KB
testcase_13 AC 5 ms
7,240 KB
testcase_14 AC 8 ms
7,344 KB
testcase_15 AC 10 ms
7,384 KB
testcase_16 AC 5 ms
7,240 KB
testcase_17 AC 8 ms
7,344 KB
testcase_18 AC 124 ms
18,480 KB
testcase_19 AC 122 ms
18,472 KB
testcase_20 AC 127 ms
18,328 KB
testcase_21 AC 162 ms
16,528 KB
testcase_22 AC 939 ms
31,572 KB
testcase_23 AC 831 ms
48,404 KB
testcase_24 AC 137 ms
12,788 KB
testcase_25 AC 137 ms
12,788 KB
testcase_26 AC 136 ms
12,260 KB
testcase_27 AC 137 ms
12,736 KB
testcase_28 AC 136 ms
12,448 KB
testcase_29 AC 6 ms
7,272 KB
testcase_30 AC 150 ms
15,744 KB
testcase_31 AC 6 ms
7,268 KB
testcase_32 AC 156 ms
15,548 KB
testcase_33 AC 157 ms
15,544 KB
testcase_34 AC 12 ms
7,448 KB
testcase_35 AC 158 ms
13,064 KB
testcase_36 AC 173 ms
13,264 KB
testcase_37 AC 174 ms
13,260 KB
testcase_38 AC 127 ms
20,292 KB
testcase_39 AC 163 ms
17,068 KB
testcase_40 AC 6 ms
7,164 KB
testcase_41 AC 6 ms
7,164 KB
testcase_42 AC 6 ms
7,172 KB
testcase_43 AC 6 ms
7,172 KB
testcase_44 AC 7 ms
7,184 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:129:23: warning: narrowing conversion of 'x1' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
  129 |             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 a[100010];
vector<P> f[100010];
int mx[1000010], p1[1000010];
int main()
{
    // clock_t start = clock();
    int n;
    cin>>n;
    vector<int> w;
    unordered_map<int, int> mp;
    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);
        }
    }
    // clock_t end = clock();
    // cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
    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++){
        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]++;
        }
    }
    // end = clock();
    // cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
    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;
        }
        // end = clock();
        // cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
    };
    // cout<<mp.size()<<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