Submission #847106


Source Code Expand

Copy
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MX = 2155;
const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;
const double PI = acos(-1.0);

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

char ispr[1 << 17];

int Sqrt(ll x) {
	int y = sqrt(x);
	while (1LL * y * y < x) y++;
	while (1LL * y * y > x) y--;
	if (1LL * y * y == x) return y;
	return -1;
}

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	vector<int> pr;
	map<ll, int> oo;
	for (int i = 2; i <= MX; i++) if (isPrime(i)) pr.push_back(i);
	for (int i = 2; i < 1 << 17; i++) {
		if (isPrime(i)) {
			ispr[i] = 1;
			oo[1LL * i * i] = 1;
		}
	}

	int n;
	while (cin >> n) {
		vector<ll> a(n);
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}

		int ans = 0;
		vector<vector<pair<int, int> > > mem(n);
		map<vector<pair<int, int> >, int> mp;
		set<vector<pair<int, int> > > used;
		for (int i = 0; i < n; i++) {
			int y = (int)pow(a[i], 1.0 / 3.0);
			while (1LL * y * y * y < a[i]) y++;
			while (1LL * y * y * y > a[i]) y--;
			if (1LL * y * y * y == a[i]) {
				if (ans == 0) ans++;
				continue;
			}

			ll x = a[i];
			vector<pair<int, int> > cur;
			for (int j = 0; j < (int)pr.size(); j++) {
				if (x % pr[j] == 0) {
					int cnt = 0;
					while (x % pr[j] == 0) {
						x /= pr[j];
						cnt++;
					}
					if (cnt % 3 != 0) cur.push_back(make_pair(pr[j], cnt % 3));
				}
			}
			if (x < 1e5 && ispr[x]) {
				cur.push_back(make_pair(x, 1)); 
				x = 1;
			}
			y = Sqrt(x);
			if (y != -1 && ispr[y]) {
				cur.push_back(make_pair(y, 2)); 
				x = 1;
			}

			if (x != 1) cur.push_back(make_pair(2e5 + i, 1));
			assert(!cur.empty());
			mem[i] = cur;
			mp[cur]++;
		}
		
		for (int i = 0; i < n; i++) {
			if (mem[i].empty()) continue;
			vector<pair<int, int> > cur = mem[i];
			if (used.find(cur) != used.end()) continue;
			vector<pair<int, int> > oth = cur;
			for (int j = 0; j < (int)oth.size(); j++) {
				oth[j].second = 3 - oth[j].second;
			}
			ans += max(mp[cur], mp[oth]);
			used.insert(cur);
			used.insert(oth);
		}
		cout << ans << endl;
	}

	return 0;
}

Submission Info

Submission Time
Task D - Anticube
User izban
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2624 Byte
Status AC
Exec Time 1522 ms
Memory 51584 KB

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 1512 ms 51584 KB
02.txt AC 1502 ms 51200 KB
03.txt AC 1519 ms 51200 KB
04.txt AC 1512 ms 51200 KB
05.txt AC 1504 ms 51200 KB
06.txt AC 1507 ms 51200 KB
07.txt AC 1512 ms 51200 KB
08.txt AC 1502 ms 51200 KB
09.txt AC 1522 ms 51200 KB
10.txt AC 1498 ms 51200 KB
11.txt AC 1067 ms 48000 KB
12.txt AC 1073 ms 48000 KB
13.txt AC 1017 ms 39936 KB
14.txt AC 1030 ms 39936 KB
15.txt AC 998 ms 39808 KB
16.txt AC 1006 ms 39808 KB
17.txt AC 816 ms 7552 KB
18.txt AC 818 ms 7552 KB
19.txt AC 819 ms 7552 KB
20.txt AC 815 ms 7552 KB
21.txt AC 1106 ms 37888 KB
22.txt AC 1109 ms 37760 KB
23.txt AC 1110 ms 37888 KB
24.txt AC 1109 ms 37888 KB
25.txt AC 1111 ms 37760 KB
26.txt AC 1108 ms 37760 KB
27.txt AC 1293 ms 41984 KB
28.txt AC 79 ms 4224 KB
29.txt AC 85 ms 4224 KB
30.txt AC 716 ms 7424 KB
31.txt AC 714 ms 7424 KB
32.txt AC 714 ms 7424 KB
33.txt AC 39 ms 1152 KB
34.txt AC 824 ms 7424 KB
35.txt AC 138 ms 4224 KB
36.txt AC 39 ms 1152 KB
37.txt AC 1052 ms 46464 KB
38.txt AC 1061 ms 46464 KB
39.txt AC 1058 ms 46464 KB
40.txt AC 1063 ms 46464 KB
41.txt AC 40 ms 1152 KB
42.txt AC 40 ms 1152 KB
43.txt AC 40 ms 1152 KB
44.txt AC 42 ms 1152 KB
45.txt AC 40 ms 1152 KB
46.txt AC 39 ms 1152 KB
47.txt AC 39 ms 1152 KB
48.txt AC 39 ms 1152 KB
s1.txt AC 39 ms 1152 KB
s2.txt AC 39 ms 1152 KB
s3.txt AC 40 ms 1152 KB