結果

問題 No.1711 Divide LCM
ユーザー chineristACchineristAC
提出日時 2021-08-13 04:19:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,626 bytes
コンパイル時間 3,127 ms
コンパイル使用メモリ 169,564 KB
実行使用メモリ 5,080 KB
最終ジャッジ日時 2023-10-17 19:52:01
合計ジャッジ時間 27,146 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 15 ms
4,348 KB
testcase_05 AC 74 ms
4,348 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 86 ms
4,348 KB
testcase_08 AC 9 ms
4,348 KB
testcase_09 AC 24 ms
4,348 KB
testcase_10 AC 4 ms
4,348 KB
testcase_11 AC 31 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 3 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 78 ms
4,760 KB
testcase_22 AC 119 ms
4,348 KB
testcase_23 AC 397 ms
4,348 KB
testcase_24 TLE -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//TLEさせたい解法

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#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>

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";
}

int pow(int n,int k){
  int res = 1;
  while (k){
    if (k&1){
      res *= n;
    }
    n *= n;
    k >>= 1;
  }
  return res;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int N;
  cin>>N;

  map<int,int> LCM;
  vec<int> A(N,1);

  int m,p,e,t;
  for (int i=0;i<N;i++){
    cin>>m;
    for (int x=0;x<m;x++){
      cin>>p>>e;
      t = pow(p,e);
      A[i] *= t;
      LCM[p];
      chmax(LCM[p],t);
    }
  }

  vec<int> P;
  for (auto [p,pe]:LCM){
    P.append(pe);
  }
  int n = P.size();

  deque<pair<ll,int>> deq = {{1,-1}};
  ll prod = -1;
  ll tmp;
  int flag;
  while (!deq.empty()){
    auto [v,k] = deq.front();
    deq.pop_front();
    for (int i=k+1;i<n;i++){
      tmp = v * (ll) P[i];
      flag = 0;
      //本来ならヤバい部分
      for (int j=0;j<N;j++){
        if (A[j]%tmp==0){
          flag = 1;
          break;
        }
      }
      if (flag){
        deq.append({tmp,i});
      }
      else{
        prod = tmp;
        deq = {};
        break;
      }
      
    }
  }

  if (prod==-1){
    cout<<-1<<endl;
    return 0;
  }

  vec<int> selected_P;
  for (int i=0;i<n;i++){
    if (prod%P[i]==0){
      selected_P.append(P[i]);
    }
  }
  int k = selected_P.size();

  vec<vec<int>> S(k,vec<int>(0));
  for (int i=0;i<N;i++){
    for (int j=0;j<k;j++){
      if (A[i]%selected_P[j]){
        S[j].append(A[i]);
        break;
      }
    }
  }

  cout<<k<<endl;
  for (int i=0;i<k;i++){
    cout<<S[i].size()<<" ";
    printv(S[i]);
  }

  
}
0