結果
問題 |
No.1711 Divide LCM
|
ユーザー |
![]() |
提出日時 | 2021-09-12 15:17:29 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,304 bytes |
コンパイル時間 | 4,017 ms |
コンパイル使用メモリ | 188,712 KB |
最終ジャッジ日時 | 2025-01-24 13:12:39 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 36 TLE * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:41:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | int m; scanf("%d", &m); | ~~~~~^~~~~~~~~~ main.cpp:45:18: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d %d", &p, &e); | ~~~~~^~~~~~~~~~~~~~~~~
ソースコード
#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() { int n; cin>>n; vector<int> w; unordered_map<int, int> mp; for(int i=0; i<n; i++){ int m; scanf("%d", &m); a[i]=1; for(int j=0; j<m; j++){ int p, e; scanf("%d %d", &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++){ // 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++; } printf("%d\n", c); 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; } } printf("%d", (int)v.size()); for(auto i:v){ printf(" %d", a[i]); } printf("\n"); } }; 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; // } bool dame=0; for(int l=0; l<n; l++){ if(a[l]%x1==0){ dame=1;break; } } if(!dame){ ans(x1);return 0; } que.push({x1, j}); } } return 0; }