結果
問題 | No.1711 Divide LCM |
ユーザー | chineristAC |
提出日時 | 2021-08-06 21:00:49 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,401 bytes |
コンパイル時間 | 6,738 ms |
コンパイル使用メモリ | 281,956 KB |
実行使用メモリ | 13,696 KB |
最終ジャッジ日時 | 2024-09-17 16:57:36 |
合計ジャッジ時間 | 17,809 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | RE | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | RE | - |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | RE | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
ソースコード
#include <iostream> #include <vector> #include <string> #include <map> #include <set> #include <queue> #include <algorithm> #include <cmath> #include <iomanip> #include <random> #include <stdio.h> #include <fstream> #include <functional> #include <cassert> #include "testlib.h" using namespace std; #define rep(i,n,c) for (int i=0;i<n;i+=c) #define append push_back #define all(x) (x).begin(), (x).end() template<class T> using vec = vector<T>; template<class T> using vvec = vec<vec<T>>; template<class T> using vvvec = vec<vvec<T>>; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<class T> bool chmin(T &a, T b){ if (a>b){ a = b; return true; } return false; } template<class T> bool chmax(T &a, T b){ if (a<b){ a = b; return true; } return false; } template<class T> T sum(vec<T> x){ T res=0; for (auto e:x){ res += e; } return res; } template<class T> void printv(vec<T> x){ for (auto e:x){ cout<<e<<" "; } cout<<"\n"; } const int M = 1000000; int spf[M+1]; void calc_spf(){ spf[1] = 1; for (int i=2;i<M+1;i++){ if (spf[i]==0){ spf[i] = i; for (int j=2*i;j<M+1;j+=i){ spf[j] = i; } } } } int pow(int n,int k){ int res = 1; while(k){ if (k&1){ res *= n; } n *= n; k >>= 1; } return res; } map<int,int> factorization(int n){ assert (1 <= n); assert (n <= M); map<int,int> res; int p,cnt; while (n!=1){ p = spf[n]; cnt = 0; while (n%p==0){ cnt += 1; n /= p; } res[p] = cnt; } return res; } const int MIN_N = 1; const int MAX_N = 1000000; int main(int argc, char* argv[]){ registerValidation(argc,argv); ios::sync_with_stdio(false); std::cin.tie(nullptr); calc_spf(); map<int,int> all_prime; int N; N = inf.readInt(MIN_N,MAX_N); inf.readEoln(); vec<int> A(N,0); vec<int> C(M+1,0); set<int> check; for (int i=0;i<N;i++){ A[i] = inf.readInt(1,M); C[A[i]] += 1; check.insert(A[i]); auto a_prime = factorization(A[i]); for(auto [p,cnt]:a_prime){ all_prime[p]; chmax(all_prime[p],cnt); } if (i!=N-1){ inf.readSpace(); } else{ inf.readEoln(); } } assert (check.size()==N); inf.readEof(); for (int i=1;i<M+1;i++){ for (int j=2*i;j<M+1;j+=i){ C[i] += C[j]; } } vec<int> P(0); for (auto [p,cnt]:all_prime){ P.append(pow(p,cnt)); } int n = P.size(); sort(all(P)); deque<pll> deq; deq.append({1ll,-1}); ll break_point = -1; while (!deq.empty()){ auto [v,k] = deq.front(); deq.pop_front(); for (int i=k+1;i<n;i++){ if (v * (ll)(P[i]) > M){ break_point = v * (ll)(P[i]); deq = {}; break; } if (C[v*P[i]]==0){ break_point = v * (ll)(P[i]); deq = {}; break; } deq.append({v*P[i],i}); } } if (break_point==-1){ cout<<-1<<endl; return 0; } vec<int> select_P={}; for (int i=0;i<n;i++){ if (break_point%P[i]==0){ select_P.append(P[i]); } } int k = select_P.size(); vec<vec<int>> S(k,vec<int>(0)); for (auto a:A){ for (int i=0;i<k;i++){ if (a%select_P[i]!=0){ S[i].append(a); break; } } } cout<<k<<endl; for (int i=0;i<k;i++){ cout<<S[i].size()<<" "; printv(S[i]); } }