Submission #848292


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

bool isPrime(int x) {
	for (int i = 2; i * i <= x; ++i)
		if (x % i == 0)
			return false;
	return true;
}

int main() {
	int n;
	scanf("%d", &n);
	vector<ll> s(n);
	forn(i, 0, n) scanf("%lld", &s[i]);
	vector<int> primes;
	forn(i, 2, 1e5 + 10)
		if (isPrime(i))
			primes.eb(i);
	vector<ll> p2, p3;
	for (int i : primes) p2.eb(1ll * i * i);
	for (int i : primes) {
		ll cb = 1ll * i * i * i;
		if (cb < 1e10 + 10) p3.eb(cb);
		else break;
	}
	map<ll, int> cnt;
	for (ll x : s) {
		for (ll j : p3) {
			if (j > x) break;
			while (x % j == 0) x /= j;
		}
		cnt[x]++;
	}
	ll ans = 0;
	map<ll, char> used;
	for (auto p : cnt) {
		ll x = p.fs;
		if (used.count(x)) continue;
		if (x == 1) {
			ans += 1;
		} else {
			used[x] = 1;
			ll inv = 1, rad = 1;
			forn(j, 0, p3.size()) {
				if (x % p2[j] == 0) {
					x /= p2[j];
					inv *= primes[j];
				}
				if (x % primes[j] == 0) {
					x /= primes[j];
					rad *= primes[j];
				}
			}
			ll root = (ll)(sqrt(x) + 0.1);
			if (root * root == x) {
				auto it = lower_bound(all(primes), root);
				if (it != primes.end() && *it == root) {
					x = 1;
					inv *= root;
				}
			}
			rad *= x;
			ld res = (ld)inv * rad * rad;
			if (res > 2e10) {
				ans += p.sn;
			} else {
				inv = inv * rad * rad;
				used[inv] = 1;
				auto ptr = cnt.find(inv);
				if (ptr == cnt.end()) ans += p.sn;
				else ans += max(p.sn, ptr->sn);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Submission Info

Submission Time
Task D - Anticube
User khadaev
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2135 Byte
Status AC
Exec Time 1690 ms
Memory 16640 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:37:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:39:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  forn(i, 0, n) scanf("%lld", &s[i]);
                                    ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1100 / 1100
Status
AC × 3
AC × 51
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 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 AC 1645 ms 13696 KB
02.txt AC 1647 ms 13696 KB
03.txt AC 1661 ms 13696 KB
04.txt AC 1668 ms 13824 KB
05.txt AC 1671 ms 13696 KB
06.txt AC 1662 ms 13696 KB
07.txt AC 1666 ms 13696 KB
08.txt AC 1690 ms 13696 KB
09.txt AC 1653 ms 13696 KB
10.txt AC 1661 ms 13696 KB
11.txt AC 871 ms 4992 KB
12.txt AC 872 ms 4992 KB
13.txt AC 522 ms 6144 KB
14.txt AC 521 ms 6144 KB
15.txt AC 522 ms 6272 KB
16.txt AC 522 ms 6144 KB
17.txt AC 82 ms 1280 KB
18.txt AC 82 ms 1280 KB
19.txt AC 82 ms 1280 KB
20.txt AC 82 ms 1280 KB
21.txt AC 1012 ms 9216 KB
22.txt AC 1009 ms 9088 KB
23.txt AC 1025 ms 9216 KB
24.txt AC 1021 ms 9216 KB
25.txt AC 1018 ms 9216 KB
26.txt AC 1026 ms 9088 KB
27.txt AC 1134 ms 16640 KB
28.txt AC 41 ms 1280 KB
29.txt AC 45 ms 1280 KB
30.txt AC 43 ms 1280 KB
31.txt AC 43 ms 1280 KB
32.txt AC 43 ms 1280 KB
33.txt AC 26 ms 512 KB
34.txt AC 76 ms 1280 KB
35.txt AC 75 ms 1280 KB
36.txt AC 26 ms 512 KB
37.txt AC 924 ms 6144 KB
38.txt AC 924 ms 6144 KB
39.txt AC 919 ms 6016 KB
40.txt AC 925 ms 6144 KB
41.txt AC 26 ms 512 KB
42.txt AC 26 ms 512 KB
43.txt AC 26 ms 512 KB
44.txt AC 26 ms 512 KB
45.txt AC 26 ms 512 KB
46.txt AC 26 ms 512 KB
47.txt AC 26 ms 512 KB
48.txt AC 26 ms 512 KB
s1.txt AC 26 ms 512 KB
s2.txt AC 26 ms 512 KB
s3.txt AC 26 ms 512 KB