Submission #847926


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
 
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
 
const int MOD = 1000000007;
double PI = 4*atan(1);

vi prime;

void genprime() {
	prime.pb(2);
	for (int i = 3; i <= 100000; ++i) {
		bool f = 0;
		for (int j = 0; j < prime.size(); ++j) {
			if (i % prime[j] == 0) {
				f = 1;
				break;
			}
			if (prime[j]*prime[j]>i) break;
		}
		if (!f) prime.pb(i);
	}
}

pair<ll,ll> fac(ll x) {
	ll x1 = 1, x2 = 1, i = 0;
	for (;i<prime.size();++i) {
		ll t = prime[i]*prime[i]*prime[i];
		if (t>x) break;
		while (x % t == 0) x /= t;
		if (x % prime[i] == 0) {
			int c = 0;
			while (x % prime[i] == 0) x /= prime[i],x1 *= prime[i],c++;
			F0R(j,3-c) x2 *= prime[i];
		}
	}
	for (;i<prime.size();++i) {
		if (prime[i]*prime[i]>x) break;
		if (x % prime[i] == 0) {
			int c = 0;
			while (x % prime[i] == 0) x /= prime[i], x1 *= prime[i],c++;
			F0R(j,3-c) x2 *= prime[i];
		}
	}
	if (x>1) x2 *= (x*x);
	return mp(x*x1,x2);
}

map<ll,pair<int,ll>> num;
map<ll,bool> done;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N; cin >> N;
	genprime();
	ll ans = 0;
	F0R(i,N) {
		ll x; cin >> x;
		pair<ll,ll> a = fac(x);
		num[a.f].f ++;
		num[a.f].s = a.s;
		// cout << x << " " << num[a.f].s << "\n";
	}
	for (auto i: num) {
		if (done[i.f]) continue;
		if (i.s.s == i.f) ans++;
		else if (num.find(i.s.s) != num.end()) {
			ans += max(num[i.s.s].f,i.s.f);
			done[i.s.s] = 1;
		} else ans += i.s.f;
	}
	cout << ans;
}

Submission Info

Submission Time
Task D - Anticube
User Benq
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1811 Byte
Status
Exec Time 5257 ms
Memory 12928 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 0 / 1100 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 3875 ms 12800 KB
02.txt 3957 ms 12800 KB
03.txt 3931 ms 12800 KB
04.txt 3901 ms 12800 KB
05.txt 3847 ms 12800 KB
06.txt 3841 ms 12800 KB
07.txt 3829 ms 12928 KB
08.txt 3899 ms 12800 KB
09.txt 3904 ms 12800 KB
10.txt 3858 ms 12800 KB
11.txt 5256 ms 1152 KB
12.txt 5257 ms 1152 KB
13.txt 2538 ms 4992 KB
14.txt 2594 ms 4992 KB
15.txt 2612 ms 4992 KB
16.txt 2597 ms 4992 KB
17.txt 88 ms 384 KB
18.txt 89 ms 384 KB
19.txt 88 ms 384 KB
20.txt 87 ms 384 KB
21.txt 5257 ms 2816 KB
22.txt 5257 ms 2816 KB
23.txt 5257 ms 2816 KB
24.txt 5257 ms 2816 KB
25.txt 5257 ms 2816 KB
26.txt 5256 ms 2816 KB
27.txt 252 ms 10752 KB
28.txt 22 ms 384 KB
29.txt 28 ms 384 KB
30.txt 38 ms 384 KB
31.txt 36 ms 384 KB
32.txt 36 ms 384 KB
33.txt 11 ms 384 KB
34.txt 71 ms 384 KB
35.txt 62 ms 384 KB
36.txt 11 ms 384 KB
37.txt 5257 ms 1280 KB
38.txt 5257 ms 1280 KB
39.txt 5257 ms 1280 KB
40.txt 5257 ms 1408 KB
41.txt 11 ms 384 KB
42.txt 11 ms 384 KB
43.txt 11 ms 384 KB
44.txt 11 ms 384 KB
45.txt 11 ms 384 KB
46.txt 12 ms 384 KB
47.txt 11 ms 384 KB
48.txt 11 ms 384 KB
s1.txt 11 ms 384 KB
s2.txt 11 ms 384 KB
s3.txt 11 ms 384 KB