Submission #846205


Source Code Expand

Copy
#include <cstdio>
#include <cassert>
#include <map>
#include <vector>
#include <cmath>
#include <set>
using namespace std;

typedef long long llong;

const llong MAX = pow(1e10, 1.0 / 3) + 10;
const int MAX2 = 1e5 + 10;

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

vector<llong> prime_cubes;
vector<int> primes;
void build_primes() {
    for (int i = 2; i < MAX; i++) {
        if (is_prime(i))
            prime_cubes.push_back(1ll * i * i * i);
    }
    for (int i = 2; i < MAX2; i++) {
        if (is_prime(i))
            primes.push_back(i);
    }
}

llong norm(llong x) {
    for (llong q : prime_cubes) {
        if (q > x)
            break;
        while (x % q == 0)
            x /= q;
    }
    return x;
}

const llong inf = 1e12;

llong mul(llong a, llong b) {
    if (inf / b < a)
        return inf;
    else
        return a * b;
}

llong contr(llong x) {
    llong y = 1;
    for (int p : primes) {
        if (1ll * p * p > x)
            break;
        if (x % p == 0) {
            if (((x / p) % p) == 0)
                y = mul(y, p), x /= p, x /= p;
            else
                y = mul(y, mul(p, p)), x /= p;
        }
    }
    if (x != 1)
        y = mul(y, mul(x, x));
    return y;
}

int main() {
    int n;
    scanf("%d", &n);
    build_primes();
    map<llong, int> cnt;
    for (int i = 0; i < n; i++) {
        llong x;
        scanf("%lld", &x);
        x = norm(x);
        cnt[x]++;
    }
    int ans = 0;
    set<llong> used;
    for (auto pr : cnt) {
        llong x = pr.first;
        int c = pr.second;
        llong y = contr(x);
        if (used.count(x))
            continue;
        if (x == y) {
            assert(x == 1);
            ans += 1;
        } else {
            if (cnt.count(y)) {
                ans += max(c, cnt[y]);
                used.insert(y);
                used.insert(x);
            } else {
                used.insert(x);
                ans += c;
            }
        }
    }
    printf("%d\n", ans);
}

Submission Info

Submission Time
Task D - Anticube
User Zlobober
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2178 Byte
Status AC
Exec Time 4148 ms
Memory 11264 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:72:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:77:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &x);
                          ^

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 2591 ms 11264 KB
02.txt AC 2610 ms 11264 KB
03.txt AC 2610 ms 11264 KB
04.txt AC 2595 ms 11264 KB
05.txt AC 2562 ms 11264 KB
06.txt AC 2572 ms 11264 KB
07.txt AC 2571 ms 11264 KB
08.txt AC 2588 ms 11264 KB
09.txt AC 2601 ms 11264 KB
10.txt AC 2557 ms 11264 KB
11.txt AC 4071 ms 3712 KB
12.txt AC 4076 ms 3712 KB
13.txt AC 849 ms 4352 KB
14.txt AC 863 ms 4352 KB
15.txt AC 863 ms 4352 KB
16.txt AC 861 ms 4352 KB
17.txt AC 80 ms 384 KB
18.txt AC 80 ms 384 KB
19.txt AC 80 ms 384 KB
20.txt AC 80 ms 384 KB
21.txt AC 3127 ms 7040 KB
22.txt AC 3125 ms 6912 KB
23.txt AC 3125 ms 7040 KB
24.txt AC 3124 ms 6912 KB
25.txt AC 3134 ms 6912 KB
26.txt AC 3126 ms 6912 KB
27.txt AC 243 ms 9344 KB
28.txt AC 39 ms 384 KB
29.txt AC 44 ms 384 KB
30.txt AC 43 ms 384 KB
31.txt AC 41 ms 384 KB
32.txt AC 41 ms 384 KB
33.txt AC 27 ms 384 KB
34.txt AC 75 ms 384 KB
35.txt AC 73 ms 384 KB
36.txt AC 26 ms 384 KB
37.txt AC 4108 ms 4480 KB
38.txt AC 4143 ms 4480 KB
39.txt AC 4110 ms 4480 KB
40.txt AC 4148 ms 4480 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 26 ms 384 KB
47.txt AC 26 ms 384 KB
48.txt AC 26 ms 384 KB
s1.txt AC 26 ms 384 KB
s2.txt AC 26 ms 384 KB
s3.txt AC 26 ms 384 KB