Submission #846893


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;
#define mp make_pair
#define pb push_back
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
LL s[100005];
vector<pair<LL, LL> > all;

bool pr[2200];
vector<int> p;

const LL INF = 3e18;

map<LL, int> ma;
map<LL, LL> pp;

int main() {
    forn(i, 2200) pr[i] = true;
    pr[0] = pr[1] = false;
    forn(i, 100) if (pr[i]) {
        for (int j = i * i; j < 2200; j += i) {
            pr[j] = false;
        }
    }
    forn(i, 2200) if (pr[i]) {
        p.pb(i);
    }
    scanf("%d", &n);
    forn(i, n) scanf("%lld", s + i);
    int ans = n;
    forn(i, n) {
        LL inv = 1;
        LL rem = s[i];
        for (int j : p) {
            LL cube = (LL)j * j * j;
            while (s[i] % cube == 0) {
                s[i] /= cube;
                rem /= cube;
            }
            int cnt = 0;
            while (s[i] % j == 0) {
                s[i] /= j;
                ++cnt;
            }
            if (cnt == 1) {
                if (inv > INF / j) inv = INF;
                else inv *= j;
                if (inv > INF / j) inv = INF;
                else inv *= j;
            } else if (cnt == 2) {
                if (inv > INF / j) inv = INF;
                else inv *= j;
            }
        }
        if (s[i] > 1) {
            int lo = 2, hi = 100000, mid;
            while (lo < hi) {
                mid = (lo + hi) >> 1;
                if ((LL)mid * mid < s[i]) {
                    lo = mid + 1;
                } else {
                    hi = mid;
                }
            }
            if ((LL)lo * lo == s[i]) {
                if (inv > INF / lo) inv = INF;
                else inv *= lo;
            } else {
                if (inv > INF / s[i]) inv = INF;
                else inv *= s[i];
                if (inv > INF / s[i]) inv = INF;
                else inv *= s[i];
            }
        }
        if (inv <= 10000000000ll) {
            all.pb(mp(rem, inv));
        }
    }
    for (auto x : all) {
        ++ma[x.first];
        pp[x.first] = x.second;
    }
    int bad = 0;
    for (auto x : ma) {
        if (x.first == 1) {
            bad += 2 * (x.second - 1);
        } else {
            auto it = ma.find(pp[x.first]);
            if (it != ma.end()) {
                bad += min(x.second, it->second);
            }
        }
    }
    assert(bad % 2 == 0);
    bad /= 2;
    ans -= bad;
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task D - Anticube
User HellKitsune
Language C++14 (GCC 5.4.1)
Score 1100
Code Size 2614 Byte
Status AC
Exec Time 1363 ms
Memory 13044 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:33:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
./Main.cpp:34:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     forn(i, 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 1168 ms 1024 KB
02.txt AC 1174 ms 1024 KB
03.txt AC 1168 ms 1024 KB
04.txt AC 1177 ms 1024 KB
05.txt AC 1192 ms 1024 KB
06.txt AC 1170 ms 1024 KB
07.txt AC 1178 ms 1024 KB
08.txt AC 1168 ms 1024 KB
09.txt AC 1178 ms 1024 KB
10.txt AC 1179 ms 1024 KB
11.txt AC 1159 ms 1024 KB
12.txt AC 1156 ms 1024 KB
13.txt AC 1170 ms 3324 KB
14.txt AC 1173 ms 3324 KB
15.txt AC 1183 ms 3324 KB
16.txt AC 1176 ms 3324 KB
17.txt AC 1211 ms 3192 KB
18.txt AC 1210 ms 3192 KB
19.txt AC 1212 ms 3192 KB
20.txt AC 1209 ms 3192 KB
21.txt AC 1184 ms 2300 KB
22.txt AC 1184 ms 2300 KB
23.txt AC 1179 ms 2300 KB
24.txt AC 1187 ms 2300 KB
25.txt AC 1185 ms 2300 KB
26.txt AC 1184 ms 2300 KB
27.txt AC 1363 ms 13044 KB
28.txt AC 1154 ms 3192 KB
29.txt AC 1145 ms 3192 KB
30.txt AC 1159 ms 3192 KB
31.txt AC 1156 ms 3192 KB
32.txt AC 1156 ms 3192 KB
33.txt AC 4 ms 256 KB
34.txt AC 1191 ms 3192 KB
35.txt AC 1176 ms 3192 KB
36.txt AC 4 ms 256 KB
37.txt AC 1162 ms 1280 KB
38.txt AC 1158 ms 1280 KB
39.txt AC 1158 ms 1280 KB
40.txt AC 1159 ms 1280 KB
41.txt AC 4 ms 256 KB
42.txt AC 6 ms 256 KB
43.txt AC 5 ms 256 KB
44.txt AC 4 ms 256 KB
45.txt AC 4 ms 256 KB
46.txt AC 4 ms 256 KB
47.txt AC 6 ms 256 KB
48.txt AC 5 ms 256 KB
s1.txt AC 5 ms 256 KB
s2.txt AC 4 ms 256 KB
s3.txt AC 4 ms 256 KB