結果

問題 No.1711 Divide LCM
ユーザー SSRSSSRS
提出日時 2021-10-15 22:50:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 3,291 bytes
コンパイル時間 2,368 ms
コンパイル使用メモリ 191,488 KB
実行使用メモリ 55,904 KB
最終ジャッジ日時 2023-10-17 20:44:27
合計ジャッジ時間 21,135 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 4 ms
4,348 KB
testcase_04 AC 25 ms
6,500 KB
testcase_05 AC 187 ms
23,696 KB
testcase_06 AC 43 ms
8,700 KB
testcase_07 AC 136 ms
18,184 KB
testcase_08 AC 32 ms
7,324 KB
testcase_09 AC 367 ms
36,532 KB
testcase_10 AC 58 ms
10,196 KB
testcase_11 AC 694 ms
55,904 KB
testcase_12 AC 60 ms
11,140 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 13 ms
4,904 KB
testcase_15 AC 24 ms
6,200 KB
testcase_16 AC 4 ms
4,348 KB
testcase_17 AC 13 ms
4,904 KB
testcase_18 AC 2,555 ms
23,204 KB
testcase_19 AC 2,547 ms
23,232 KB
testcase_20 AC 2,538 ms
23,220 KB
testcase_21 AC 342 ms
42,024 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
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 #

#include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> &ans, bool &ok, int &cnt, vector<vector<vector<int>>> &ng, vector<int> &curr, int sz, int p){
  if (p == cnt){
    if (curr.size() == sz){
      auto itr = lower_bound(ng[sz].begin(), ng[sz].end(), curr);
      if (itr == ng[sz].end()){
        ans = curr;
        ok = true;
      } else if (*itr != curr){
        ans = curr;
        ok = true;
      }
    }
  } else {
    dfs(ans, ok, cnt, ng, curr, sz, p + 1);
    if (ok){
      return;
    }
    if (curr.size() < sz){
      curr.push_back(p);
      dfs(ans, ok, cnt, ng, curr, sz, p + 1);
      curr.pop_back();
    }
  }
}
int main(){
  int N;
  cin >> N;
  vector<int> m(N);
  vector<vector<int>> p(N), e(N);
  for (int i = 0; i < N; i++){
    cin >> m[i];
    p[i] = vector<int>(m[i]);
    e[i] = vector<int>(m[i]);
    for (int j = 0; j < m[i]; j++){
      cin >> p[i][j] >> e[i][j];
    }
  }
  vector<int> P;
  for (int i = 0; i < N; i++){
    for (int j = 0; j < m[i]; j++){
      P.push_back(p[i][j]);
    }
  }
  sort(P.begin(), P.end());
  P.erase(unique(P.begin(), P.end()), P.end());
  int cnt = P.size();
  for (int i = 0; i < N; i++){
    for (int j = 0; j < m[i]; j++){
      p[i][j] = lower_bound(P.begin(), P.end(), p[i][j]) - P.begin();
    }
  }
  vector<int> mx(cnt, -1);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < m[i]; j++){
      mx[p[i][j]] = max(mx[p[i][j]], e[i][j]);
    }
  }
  vector<vector<int>> s(N);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < m[i]; j++){
      if (mx[p[i][j]] == e[i][j]){
        s[i].push_back(p[i][j]);
      }
    }
  }
  bool ok = true;
  for (int i = 0; i < N; i++){
    if (s[i].size() == cnt){
      ok = false;
    }
  }
  if (!ok){
    cout << -1 << endl;
  } else {
    vector<vector<vector<int>>> ng(10);
    for (int i = 0; i < N; i++){
      int cnt2 = s[i].size();
      for (int j = 0; j < (1 << cnt2); j++){
        int sz = __builtin_popcount(j);
        vector<int> S2;
        for (int k = 0; k < cnt2; k++){
          if ((j >> k & 1) == 1){
            S2.push_back(s[i][k]);
          }
        }
        ng[sz].push_back(S2);
      }
    }
    for (int i = 0; i < 10; i++){
      sort(ng[i].begin(), ng[i].end());
      ng[i].erase(unique(ng[i].begin(), ng[i].end()), ng[i].end());
    }
    vector<int> ans;
    for (int i = 1; i <= 10; i++){
      vector<int> curr;
      bool ok2 = false;
      dfs(ans, ok2, cnt, ng, curr, i, 0);
      if (ok2){
        break;
      }
    }
    vector<int> A(N, 1);
    for (int i = 0; i < N; i++){
      for (int j = 0; j < m[i]; j++){
        for (int k = 0; k < e[i][j]; k++){
          A[i] *= P[p[i][j]];
        }
      }
    }
    int k = ans.size();
    vector<vector<int>> S(k);
    for (int i = 0; i < N; i++){
      for (int j = 0; j < k; j++){
        bool ok2 = true;
        int cnt2 = s[i].size();
        for (int l = 0; l < cnt2; l++){
          if (s[i][l] == ans[j]){
            ok2 = false;
          }
        }
        if (ok2){
          S[j].push_back(A[i]);
          break;
        }
      }
    }
    cout << k << endl;
    for (int i = 0; i < k; i++){
      int n = S[i].size();
      cout << n;
      for (int j = 0; j < n; j++){
        cout << ' ' << S[i][j];
      }
      cout << endl;
    }
  }
}
0