結果

問題 No.234 めぐるはめぐる (4)
ユーザー heno239heno239
提出日時 2020-08-19 02:58:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 6,554 bytes
コンパイル時間 2,470 ms
コンパイル使用メモリ 146,140 KB
実行使用メモリ 85,260 KB
最終ジャッジ日時 2024-10-12 03:29:49
合計ジャッジ時間 6,672 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other TLE * 1 -- * 1
権限があれば一括ダウンロードができます

ソースコード

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

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;
//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 998244353;
const ll INF = mod * mod/300;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
ll mod_pow(ll x, ll n, ll m) {
ll res = 1;
while (n) {
if (n & 1)res = res * x % m;
x = x * x % m; n >>= 1;
}
return res;
}
struct modint {
ll n;
modint() :n(0) { ; }
modint(ll m) :n(m) {
if (n >= mod)n %= mod;
else if (n < 0)n = (n % mod + mod) % mod;
}
operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint& a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint& a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint& a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, ll n) {
if (n == 0)return modint(1);
modint res = (a * a) ^ (n / 2);
if (n % 2)res = res * a;
return res;
}
ll inv(ll a, ll p) {
return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 22;
modint fact[max_n], factinv[max_n];
void init_f() {
fact[0] = modint(1);
for (int i = 0; i < max_n - 1; i++) {
fact[i + 1] = fact[i] * modint(i + 1);
}
factinv[max_n - 1] = modint(1) / fact[max_n - 1];
for (int i = max_n - 2; i >= 0; i--) {
factinv[i] = factinv[i + 1] * modint(i + 1);
}
}
modint comb(int a, int b) {
if (a < 0 || b < 0 || a < b)return 0;
return fact[a] * factinv[b] * factinv[a - b];
}
ll gcd(ll a, ll b) {
if (a < b)swap(a, b);
while (b) {
ll r = a % b; a = b; b = r;
}
return a;
}
struct uf {
private:
vector<int> par, ran;
public:
uf(int n) {
par.resize(n, 0);
ran.resize(n, 0);
rep(i, n) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x)return x;
else return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)return;
if (ran[x] < ran[y]) {
par[x] = y;
}
else {
par[y] = x;
if (ran[x] == ran[y])ran[x]++;
}
}
bool same(int x, int y) {
return find(x) == find(y);
}
};
void debug(vector<int> v) {
rep(i, v.size()) {
if (i > 0)cout << " ";
cout << v[i];
}
cout << "\n";
}
vector<int> ch[1 << 10];
void init() {
rep(i, (1 << 10)) {
vector<int> v;
rep(j, 10)if (i & (1 << j)) {
v.push_back(j);
}
int len = v.size();
rep(j, (1 << len)){
int s = 0;
rep(k, len) {
if (j & (1 << k)) {
s |= (1 << v[k]);
}
}
ch[i].push_back(s);
}
}
}
void solve() {
init(); debug(ch[3]);
vector<ll>memo(12);
memo[1] = 1;
cout << memo[1] << "\n";
map<vector<int>, ll> dp;
dp[{1}] = 1;
for (int n = 2; n <= 11; n++) {
map<vector<int>, ll> nex;
for (pair<vector<int>, ll> p : dp) {
vector<int> v = p.first; ll val = p.second;
if (v.empty())continue; //assert(v.size());
//cout << "hello\n"; debug(v);
vector<bool> exi(n - 1);
for (int s : v)rep(j, n - 1)if (s & (1 << j))exi[j] = true;
vector<int> rs;
rep(j, n - 1)if (!exi[j])rs.push_back(j);
int len = rs.size();
vector<int> cur;
function<void(int)> dfs = [&](int id) {
if (id == v.size()) {
rep(j,1<<len) {
vector<int> cop = cur;
rep(k, len) {
if (j & (1 << k))cop.push_back(1 << rs[k]);
}
sort(all(cop));
nex[cop] += val;
if (cop.size() == 1)memo[n] += val;
}
/*cout << "from\n";
debug(v);
cout << "to\n";
debug(cop);*/
return;
}
int s = v[id];
for (int c : ch[s])if (c > 0) {
cur.push_back(c);
dfs(id + 1);
cur.pop_back();
}
};
dfs(0);
}
rep(i, (1 << n - 1)) {
vector<int> v;
rep(j, n - 1)if (i & (1 << j))v.push_back(1<<j);
nex[v] += 1;
if (v.size() == 1)memo[n] += 1;
}
dp.clear();
for (pair<vector<int>, ll> p : nex) {
/*cout << "start\n";
debug(p.first);
cout << p.second << "\n";
ll rec = memo[n];*/
vector<int> v = p.first; ll val = p.second;
uf u(2 * n - 1);
vector<bool> exi(n - 1, false);
for (int s : v) {
int pre = -1;
rep(j, n - 1) {
if (s & (1 << j)) {
if (pre >= 0) {
u.unite(pre + n, j + n);
}
pre = j;
exi[j] = true;
}
}
}
rep(i, (1 << n)) {
uf z = u;
rep(j, n)if (i & (1 << j)) {
if (j - 1 >= 0) {
if(exi[j-1])z.unite(j - 1 + n, j);
}
if (j < n - 1) {
if(exi[j])z.unite(j + n, j);
}
}
vector<int> mem(2 * n - 1);
rep(j, n)if (i & (1 << j)) {
mem[z.find(j)] |= (1 << j);
}
bool valid = true;
for (int s : v) {
rep(j, n - 1)if (s & (1 << j)) {
int p = z.find(n + j);
if (mem[p] == 0)valid = false;
break;
}
}
if (valid) {
vector<int> to;
for (int me : mem) {
if (me > 0)to.push_back(me);
}
sort(all(to));
if (n == 4) {
cout << "from\n";
debug(v); debug(to);
}
dp[to] += val;
if(to.size()==1)memo[n] += val;
}
}
//cout << memo[n] - rec << "\n";
}
cout << dp.size() << " " << nex.size() << "\n";
/*for (pair<vector<int>, ll> p : nex) {
cout << "start\n";
debug(p.first);
cout << p.second << "\n";
}
for (pair<vector<int>, ll> p : dp) {
cout << "start2\n";
debug(p.first);
cout << p.second << "\n";
}*/
cout << memo[n] << "\n";
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
//cout << fixed << setprecision(10);
//init_f();
//expr();
//int t; cin >> t; rep(i, t)
//while (cin >> n >> m>>s1>>s2>>t, n)
solve();
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0