結果

問題 No.1711 Divide LCM
ユーザー 沙耶花
提出日時 2021-10-15 22:57:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,960 ms / 4,000 ms
コード長 3,609 bytes
コンパイル時間 5,156 ms
コンパイル使用メモリ 272,992 KB
最終ジャッジ日時 2025-01-25 01:05:33
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
struct rolling_hash{
long long t_hash;
static vector<long long> power;
static const long long MOD = (1LL<<61)-1;
static const long long b = 123456;
int sz;
rolling_hash(){
sz = 0;
t_hash = 0;
}
rolling_hash(long long c){
sz = 1;
t_hash = b*c;
}
long long mul(__int128 x,__int128 y){
__int128 t = x*y;
t = (t>>61) + (t&MOD);
if(t>=MOD)t -= MOD;
return t;
}
long long get_pow(int sz){
if(power.size()>sz)return power[sz];
while(power.size()<=sz){
if(power.size()==0)power.push_back(1);
else power.push_back(mul(power.back(),b));
}
return power.back();
}
rolling_hash &operator+=(const rolling_hash &another){
(*this).t_hash = mul((*this).t_hash,get_pow(another.sz));
(*this).t_hash += another.t_hash;
if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
(*this).sz += another.sz;
return (*this);
}
rolling_hash operator+(const rolling_hash &another)const{
return (rolling_hash(*this)+=another);
}
rolling_hash &operator-=(const rolling_hash &another){
(*this).t_hash += MOD - mul(another.t_hash,get_pow((*this).sz-another.sz));
if((*this).t_hash>=MOD)(*this).t_hash -= MOD;
(*this).sz -= another.sz;
return (*this);
}
rolling_hash operator-(const rolling_hash &another)const{
return (rolling_hash(*this)-=another);
}
bool operator<(const rolling_hash &another)const{
if((*this).t_hash!=another.t_hash)return (*this).t_hash<another.t_hash;
return (*this).sz<another.sz;
}
bool operator==(const rolling_hash &another)const{
return ((*this).t_hash==another.t_hash && (*this).sz==another.sz);
}
};
vector<long long> rolling_hash::power;
int main(){
int N;
cin>>N;
vector<map<int,int>> mp(N);
map<int,int> LCA;
vector<long long> v(N,1);
rep(i,N){
int m;
cin>>m;
rep(j,m){
int p,e;
cin>>p>>e;
mp[i][p] = e;
LCA[p] = max(LCA[p],e);
rep(k,e)v[i] *= p;
}
}
map<int,int> pos;
int cur = 0;
vector<int> ps(LCA.size());
for(auto a:LCA){
pos[a.first] = cur;
ps[cur] = a.first;
cur++;
}
set<rolling_hash> S;
vector<vector<int>> tt(N);
rep(i,N){
vector<int> t;
for(auto a:mp[i]){
if(a.second == LCA[a.first]){
t.push_back(pos[a.first]);
}
}
sort(t.begin(),t.end());
rolling_hash h;
rep(j,t.size())h += rolling_hash(t[j]);
tt[i] = t;
if(S.count(h))continue;
rep(j,1<<t.size()){
rolling_hash th;
rep(k,t.size()){
if((j>>k)&1)th += rolling_hash(t[k]);
}
S.insert(th);
}
}
//cout<<'a'<<endl;
vector<vector<int>> t(cur);
rep(i,cur)t[i] = {i};
while(true){
if(t.size()==0){
cout<<-1<<endl;
return 0;
}
vector<vector<int>> nt;
rep(i,t.size()){
int last = t[i].back();
for(int j=last+1;j<cur;j++){
vector<int> temp = t[i];
temp.push_back(j);
rolling_hash h;
rep(k,temp.size())h += rolling_hash(temp[k]);
if(!S.count(h)){
cout<<temp.size()<<endl;
vector<vector<int>> ans(temp.size());
rep(i,N){
rep(j,temp.size()){
if(binary_search(tt[i].begin(),tt[i].end(),temp[j]))continue;
ans[j].push_back(v[i]);
break;
}
}
rep(i,temp.size()){
cout<<ans[i].size();
rep(j,ans[i].size()){
cout<<' ';
cout<<ans[i][j];
}
cout<<endl;
}
return 0;
}
nt.push_back(temp);
}
}
swap(t,nt);
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0