Submission #1776845


Source Code Expand

#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair

ll read()
{
    ll v = 0, f = 1;
    char c = getchar();
    while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();}
    while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
    return v * f;
}

map<ll, ll> mp;
ll pr[101000], vis[101000], a[101000], b[101000], n;

const ll INF = 1e12;

const ll p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
inline ll mul(ll a, ll b, ll p)
{
    ll t = ll((double) a * b / (double) p + 0.5);
    t = a * b - p * t;
    return t < 0 ? t + p : t;
}
inline ll pw(ll a, ll b)
{
    ll re = 1;
    while (b)
    {
        if (b & 1)
            re *= a;
        a *= a;
        b >>= 1;
    }
    return re;
}
inline ll pw(ll a, ll b, ll p)
{
    ll re = 1;
    while (b)
    {
        if (b & 1)
            re = mul(re, a, p);
        a = mul(a, a, p);
        b >>= 1;
    }
    return re;
}
inline bool millerRabbin(ll n)
{
    if (n < 29)
    {
        for (int i = 0; i < 9; i++)
            if (p[i] == n)
                return 1;
        return 0;
    }
    ll d = n - 1;
    int s = 0;
    while (d % 2 == 0)
        d /= 2, s++;
    for (int i = 0; i < 9; i++)
    {
        ll j = p[i];
        ll t = pw(j, d, n);
        for (int is = 0; is < s; is++)
        {
            ll tmp = mul(t, t, n);
            if (tmp == 1)
                if (t != 1 && t != n - 1)
                    return 0;
            t = tmp;
        }
        if (t != 1) return 0;
    }
    return 1;
}
ll num[10000];
ll rho(ll n)
{
	ll c = rand() % (n - 1) + 1;
	ll p1 = 1, p2 = 1, k = 1, t = 1;
	for (ll i = 1; t == 1; i++)
	{
		p1 = (mul(p1, p1, n) + c) % n;
		if (p1 == p2) return 1;
		t = __gcd(abs(p1 - p2), n);
		if (i == k) k += k, p2 = p1;
	}
	return t;
}
void cal(ll n)
{
    if (millerRabbin(n))
    {
        num[++num[0]] = n;
        return ;
    }
    ll t = 1;
    while (t == 1)
        t = rho(n);
    cal(t);
    cal(n / t);
}

int main()
{
    n = read();
    for (int i = 2; i <= 100000; i++)
    {
        if (!vis[i])
            pr[++pr[0]] = i;
        for (int j = 1; j <= pr[0] && i * pr[j] <= 100000; j++)
        {
            vis[i * pr[j]] = 1;
            if (i % pr[j] == 0) break;
        }
    }
    for (int i = 1; i <= n; i++)
    {
        ll u = read();
        num[0] = 0;
        cal(u);
        map<ll, int> t;
        for (int j = 1; j <= num[0]; j++)
            t[num[j]]++;
        ll p1 = 1, p2 = 1;
        for (map<ll, int> :: iterator j = t.begin(); j != t.end(); j++)
        {
            int t1 = (*j).second % 3;
            int t2 = (3 - t1) % 3;
            p1 *= pw((*j).first, t1);
            if (pw((*j).first, t2) <= INF / p2)
                p2 *= pw((*j).first, t2);
            else
                p2 = INF;
        }
        a[i] = p1;
        b[i] = p2;
        if (p1 > 1)
            mp[p1]++;
    }
    ll ans = 0;
    set<ll> S;
    for (int i = 1; i <= n; i++)
        if (a[i] > 1 && !S.count(a[i]))
        {
            ans += max(mp[a[i]], mp[b[i]]);
            S.insert(a[i]);
        }
    ans /= 2;
    ll flg = 0;
    for (int i = 1; i <= n; i++)
        if (a[i] == 1) flg = 1;
    printf("%lld\n", ans + flg);
}

Submission Info

Submission Time
Task D - Anticube
User Misaka10032
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3697 Byte
Status RE
Exec Time 2088 ms
Memory 13824 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1100
Status
AC × 1
RE × 2
AC × 7
WA × 23
RE × 21
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 WA 1931 ms 13824 KB
02.txt WA 1895 ms 13824 KB
03.txt WA 1908 ms 13824 KB
04.txt WA 1901 ms 13824 KB
05.txt WA 1906 ms 13824 KB
06.txt WA 1911 ms 13824 KB
07.txt WA 1908 ms 13824 KB
08.txt WA 1897 ms 13824 KB
09.txt WA 1915 ms 13824 KB
10.txt WA 1901 ms 13824 KB
11.txt WA 543 ms 6784 KB
12.txt WA 542 ms 6784 KB
13.txt WA 2067 ms 8320 KB
14.txt WA 2086 ms 8320 KB
15.txt WA 2088 ms 8320 KB
16.txt WA 2083 ms 8320 KB
17.txt RE 165 ms 1280 KB
18.txt RE 107 ms 1152 KB
19.txt RE 111 ms 1152 KB
20.txt RE 204 ms 1280 KB
21.txt RE 603 ms 3456 KB
22.txt RE 206 ms 1664 KB
23.txt RE 803 ms 4224 KB
24.txt RE 156 ms 1408 KB
25.txt RE 278 ms 1920 KB
26.txt RE 126 ms 1280 KB
27.txt RE 98 ms 1152 KB
28.txt RE 98 ms 1152 KB
29.txt AC 102 ms 2688 KB
30.txt WA 67 ms 2688 KB
31.txt AC 71 ms 2688 KB
32.txt AC 71 ms 2688 KB
33.txt WA 3 ms 1152 KB
34.txt WA 1240 ms 2688 KB
35.txt AC 1076 ms 2688 KB
36.txt RE 98 ms 1152 KB
37.txt RE 574 ms 4480 KB
38.txt WA 683 ms 7808 KB
39.txt WA 685 ms 7808 KB
40.txt WA 688 ms 7936 KB
41.txt AC 3 ms 1152 KB
42.txt AC 3 ms 1152 KB
43.txt WA 3 ms 1152 KB
44.txt RE 98 ms 1152 KB
45.txt RE 98 ms 1152 KB
46.txt RE 99 ms 1152 KB
47.txt RE 99 ms 1152 KB
48.txt RE 98 ms 1152 KB
s1.txt RE 98 ms 1152 KB
s2.txt AC 3 ms 1152 KB
s3.txt RE 99 ms 1152 KB