QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#442511#8747. 朔望MindevelopedTL 0ms0kbC++141.9kb2024-06-15 12:30:302024-06-15 12:30:30

Judging History

你现在查看的是最新测评结果

  • [2024-06-15 12:30:30]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-06-15 12:30:30]
  • 提交

answer

#include<bits/stdc++.h>
#define F(i, x, y) for (int (i) = (x);(i) <= (y);(i)++)
#define R(i, x, y) for (int (i) = (x);(i) >= (y);(i)--)
using namespace std;

const int mod = 1e9 + 7;
int t[25], n, w[25];
unordered_map<int, int> dc[25], sdc[25][25];
int qp (int x, int y) {
	int a = 1, u = x;
	while (y) {
		if (y % 2) a = 1LL * a * u % mod;
		u = 1LL * u * u % mod;
		y /= 2;
	}
	return a;
}
int get_contrib (int x) {
	if (x == (x & -x)) return 0;
	int ls = 0;
	bool first = true;
	unordered_map<int, int> lcm;
	F (i, 1, n) {
		if (x & (1 << (i - 1))) {
			if (ls) {
				unordered_map<int, int> cur;
				cur[2]--;
				for (pair<int, int> j: dc[ls]) cur[j.first] += j.second;
				for (pair<int, int> j: dc[i]) cur[j.first] += j.second;
				for (pair<int, int> j: sdc[ls][i]) cur[j.first] -= j.second;
				if (!first) {
					for (pair<int, int> j: cur) lcm[j.first] = max (lcm[j.first], j.second);
				}
				else lcm = cur;
				first = false;
			}
			ls = i;
		}
	}
	int ans = 1;
	for (pair<int, int> i: lcm) {
		ans = 1LL * ans * qp (i.first, (mod - 1 - i.second) % (mod - 1)) % mod; 
	}
	cout << "The weight of " << x << " is " << qp (ans, mod - 2) << "\n";
	return ans;
}
void decomp (int x, unordered_map<int, int> &res) {
	res.clear ();
	F (i, 2, sqrt (x)) {
		while (x % i == 0) {
			res[i]++;
			x /= i;
		}
	}
	if (x > 1) res[x]++;
}
int popc (int x) {
	return x ? (x & 1) + popc (x >> 1) : 0;
}
int main () {
	ios::sync_with_stdio (false);
	cin.tie (0);
	cin >> n;
	F (i, 1, n) {
		cin >> t[i];
	}
	F (i, 1, n) {
		decomp (t[i], dc[i]);
		F (j, i + 1, n) {
			decomp (abs (t[i] - t[j]), sdc[i][j]);
		}
	}
	F (i, 2, n) {
		cin >> w[i];
	}
	R (i, n, 2) {
		w[i] = (w[i] + 1LL * (mod - w[i - 1]) * i % mod) % mod;
	}
	int ans = 0;
	F (i, 0, (1 << n) - 1) {
		ans += 1LL * get_contrib (i) * w[popc (i)] % mod;
		ans %= mod;
	}
	cout << ans << "\n";
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

20
73415948 190825288 205086969 242726140 280691039 291234110 341933576 379938879 399631744 420807939 421811250 486105558 605031352 645495854 714594262 775221445 793534057 818237037 926135349 940293639
108200337 125078426 163639475 261733041 280562529 287327830 310288774 415301468 419144734 46329977...

output:

The weight of 3 is 567288549
The weight of 5 is 373171257
The weight of 6 is 579704446
The weight of 7 is 248413565
The weight of 9 is 705162756
The weight of 10 is 414340766
The weight of 11 is 501375689
The weight of 12 is 728852402
The weight of 13 is 291269858
The weight of 14 is 757019117
The w...

result: