Submission #846389


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 = 1e5 + 3;
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;
}

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

	vector<int> pr;
	for (int i = 2; i <= MX; i++) if (isPrime(i)) pr.push_back(i);

	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 != 1) cur.push_back(make_pair(MX + 10 + 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 0
Code Size 2137 Byte
Status TLE
Exec Time 5254 ms
Memory 8064 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1100
Status
AC × 3
AC × 16
TLE × 35
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 TLE 5254 ms 8064 KB
02.txt TLE 5254 ms 8064 KB
03.txt TLE 5254 ms 8064 KB
04.txt TLE 5254 ms 8064 KB
05.txt TLE 5254 ms 8064 KB
06.txt TLE 5254 ms 8064 KB
07.txt TLE 5254 ms 8064 KB
08.txt TLE 5254 ms 8064 KB
09.txt TLE 5254 ms 8064 KB
10.txt TLE 5254 ms 8064 KB
11.txt TLE 5254 ms 7680 KB
12.txt TLE 5254 ms 7680 KB
13.txt TLE 5254 ms 7424 KB
14.txt TLE 5254 ms 7424 KB
15.txt TLE 5254 ms 7424 KB
16.txt TLE 5254 ms 7424 KB
17.txt TLE 5253 ms 4352 KB
18.txt TLE 5253 ms 4352 KB
19.txt TLE 5253 ms 4352 KB
20.txt TLE 5253 ms 4352 KB
21.txt TLE 5254 ms 6912 KB
22.txt TLE 5254 ms 6912 KB
23.txt TLE 5254 ms 6912 KB
24.txt TLE 5254 ms 6912 KB
25.txt TLE 5254 ms 6912 KB
26.txt TLE 5254 ms 6912 KB
27.txt TLE 5254 ms 7168 KB
28.txt AC 64 ms 3456 KB
29.txt AC 70 ms 3456 KB
30.txt TLE 5253 ms 4352 KB
31.txt TLE 5254 ms 4352 KB
32.txt TLE 5253 ms 4352 KB
33.txt AC 26 ms 384 KB
34.txt TLE 5253 ms 4352 KB
35.txt AC 125 ms 3456 KB
36.txt AC 25 ms 384 KB
37.txt TLE 5254 ms 7552 KB
38.txt TLE 5254 ms 7552 KB
39.txt TLE 5254 ms 7552 KB
40.txt TLE 5254 ms 7552 KB
41.txt AC 26 ms 384 KB
42.txt AC 26 ms 384 KB
43.txt AC 26 ms 384 KB
44.txt AC 26 ms 384 KB
45.txt AC 26 ms 384 KB
46.txt AC 25 ms 384 KB
47.txt AC 25 ms 384 KB
48.txt AC 26 ms 384 KB
s1.txt AC 27 ms 384 KB
s2.txt AC 26 ms 384 KB
s3.txt AC 27 ms 384 KB