Submission #1776825


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;
        if (u > 1)
            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;
        mp[p1]++;
    }
    ll ans = 0;
    for (int i = 1; i <= n; i++)
        ans += max(mp[a[i]], mp[b[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 3584 Byte
Status WA
Exec Time 2098 ms
Memory 12928 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1100
Status
AC × 1
WA × 2
AC × 4
WA × 47
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 1871 ms 9088 KB
02.txt WA 1856 ms 9088 KB
03.txt WA 1872 ms 9088 KB
04.txt WA 1881 ms 9088 KB
05.txt WA 1866 ms 9088 KB
06.txt WA 1856 ms 9088 KB
07.txt WA 1864 ms 9088 KB
08.txt WA 1854 ms 9088 KB
09.txt WA 1867 ms 9088 KB
10.txt WA 1856 ms 9088 KB
11.txt WA 538 ms 5376 KB
12.txt WA 538 ms 5376 KB
13.txt WA 2074 ms 6528 KB
14.txt WA 2098 ms 6528 KB
15.txt WA 2098 ms 6656 KB
16.txt WA 2092 ms 6528 KB
17.txt WA 816 ms 2688 KB
18.txt WA 818 ms 2688 KB
19.txt WA 817 ms 2688 KB
20.txt WA 816 ms 2688 KB
21.txt WA 1342 ms 7936 KB
22.txt WA 1345 ms 7936 KB
23.txt WA 1331 ms 8064 KB
24.txt WA 1337 ms 7936 KB
25.txt WA 1358 ms 7936 KB
26.txt WA 1351 ms 7936 KB
27.txt WA 422 ms 12928 KB
28.txt WA 7 ms 2688 KB
29.txt WA 102 ms 2688 KB
30.txt WA 66 ms 2688 KB
31.txt WA 71 ms 2688 KB
32.txt WA 71 ms 2688 KB
33.txt WA 3 ms 1152 KB
34.txt WA 1234 ms 2688 KB
35.txt WA 1071 ms 2688 KB
36.txt WA 3 ms 1152 KB
37.txt WA 678 ms 6016 KB
38.txt WA 688 ms 6016 KB
39.txt WA 685 ms 6016 KB
40.txt WA 688 ms 6016 KB
41.txt WA 3 ms 1152 KB
42.txt AC 3 ms 1152 KB
43.txt WA 3 ms 1152 KB
44.txt AC 3 ms 1152 KB
45.txt WA 3 ms 1152 KB
46.txt AC 3 ms 1152 KB
47.txt WA 3 ms 1152 KB
48.txt WA 3 ms 1152 KB
s1.txt AC 3 ms 1152 KB
s2.txt WA 3 ms 1152 KB
s3.txt WA 3 ms 1152 KB