提出 #846858


ソースコード 拡げる

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

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

#ifdef __WIN32
#define LLFORMAT "I64"
#define Rand() ((rand() << 15) | rand())
#else
#define LLFORMAT "ll"
#define Rand() (rand())
#endif

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

LL mul(LL b, LL e, LL m)
{
	b %= m;
	e %= m;
	LL t = b * e - LL((long double)b * e / m) * m;
	while (t < 0) t += m;
	while (t >= m) t -= m;
	return t;
}
 
LL Fpm(LL b, LL e, LL m)
{
	LL t = 1;
	for ( ; e; e >>= 1, b = mul(b, b, m))
		if (e & 1) t = mul(t, b, m);
	return t;
}
 
bool witness(int a, LL b)
{
	if (a == b) return 1;
	LL s = b - 1;
	int cnt = 0;
	while (!(s & 1)) s >>= 1, ++cnt;
	LL tmp = Fpm(a, s, b);
	if (tmp == 1) return 1;
	while (cnt)
	{
		if (tmp == b - 1) return 1;
		--cnt;
		tmp = mul(tmp, tmp, b);
		if (tmp == 1) return 0;
	}
	return 0;
}
 
const int p[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}, pn = sizeof(p) / sizeof(p[0]);

bool isprime(LL x)
{
	if (!x) return 0;
	if (x == 1) return 0;
	REP(i, 0, pn) 
	{
		if (!witness(p[i], x)) return 0;
	}
	return 1;
}

set<LL> all;

inline void rho(LL x)
{
	if (isprime(x))
	{
		all.insert(x);
		return;
	}
	if (x <= 100000000)
	{
		for (int i = 2; i * i <= x; ++i)
		{
			if (!(x % i)) all.insert(i);
			while (!(x % i)) x /= i;
		}
		if (x > 1) all.insert(x);
		return;
	}
	while (1)
	{
		LL x0 = 0, x1 = 0;
		int c = Rand();
		LL d = 1;
		int cnt = 0;
		while (d == 1)
		{
			x0 = mul(x0, x0, x);
			(x0 += c) %= x;
			d = __gcd(abs(x0 - x1), x);
			++cnt;
			if (!(cnt & (cnt - 1))) x1 = x0;
		}
		if (d != x)
		{
			rho(d);
			rho(x / d);
			break;
		}
	}
}

inline void decom(LL x)
{
	all.clear();
	REP(i, 0, pn)
	{
		if (!(x % p[i])) all.insert(p[i]);
		while (!(x % p[i])) x /= p[i];
	}
	if (x > 1) rho(x);
}

const int maxn = 100000;

int n;
LL a[maxn + 5];

map<vector<pair<LL, int> >, int> num;

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%d", &n);
	int ret = 0;
	REP(i, 0, n) 
	{
		scanf("%" LLFORMAT "d", a + i);
		decom(a[i]);
		vector<pair<LL, int> > tmp;
		for (auto u : all)
		{
			int cnt = 0;
			while (!(a[i] % u)) a[i] /= u, ++cnt;
			cnt %= 3;
			if (cnt) tmp.pb(mp(u, cnt));
		}
		if (SZ(tmp)) ++num[tmp];
		else ret = 1;
	}
	for (auto u : num) if (u.y)
	{
		vector<pair<LL, int> > tmp;
		for (auto v : u.x) tmp.pb(mp(v.x, 3 - v.y));
		if (num.count(tmp))
		{
			int val = num[tmp];
			ret += max(u.y, val);
			num[tmp] = 0;
		}
		else ret += u.y;
	}
	printf("%d\n", ret);
	return 0;
}

提出情報

提出日時
問題 D - Anticube
ユーザ matthew99
言語 C++14 (GCC 5.4.1)
得点 1100
コード長 3118 Byte
結果 AC
実行時間 4767 ms
メモリ 15488 KB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:144:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:148:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%" LLFORMAT "d", a + i);
                                 ^

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 1100 / 1100
結果
AC × 3
AC × 51
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
01.txt AC 4096 ms 15488 KB
02.txt AC 4021 ms 15488 KB
03.txt AC 4030 ms 15488 KB
04.txt AC 4030 ms 15488 KB
05.txt AC 4021 ms 15488 KB
06.txt AC 4035 ms 15488 KB
07.txt AC 4061 ms 15488 KB
08.txt AC 4057 ms 15488 KB
09.txt AC 4061 ms 15488 KB
10.txt AC 4014 ms 15488 KB
11.txt AC 2162 ms 4480 KB
12.txt AC 2166 ms 4480 KB
13.txt AC 4628 ms 5120 KB
14.txt AC 4698 ms 5120 KB
15.txt AC 4715 ms 5120 KB
16.txt AC 4767 ms 5120 KB
17.txt AC 240 ms 1024 KB
18.txt AC 240 ms 1024 KB
19.txt AC 239 ms 1024 KB
20.txt AC 238 ms 1024 KB
21.txt AC 2841 ms 8576 KB
22.txt AC 2823 ms 8576 KB
23.txt AC 2828 ms 8576 KB
24.txt AC 2808 ms 8576 KB
25.txt AC 2842 ms 8576 KB
26.txt AC 2834 ms 8576 KB
27.txt AC 864 ms 12160 KB
28.txt AC 39 ms 1024 KB
29.txt AC 68 ms 1024 KB
30.txt AC 96 ms 1024 KB
31.txt AC 95 ms 1024 KB
32.txt AC 95 ms 1024 KB
33.txt AC 4 ms 256 KB
34.txt AC 224 ms 1024 KB
35.txt AC 188 ms 1024 KB
36.txt AC 4 ms 256 KB
37.txt AC 2283 ms 5376 KB
38.txt AC 2286 ms 5504 KB
39.txt AC 2273 ms 5376 KB
40.txt AC 2283 ms 5376 KB
41.txt AC 4 ms 256 KB
42.txt AC 4 ms 256 KB
43.txt AC 4 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 4 ms 256 KB
48.txt AC 4 ms 256 KB
s1.txt AC 4 ms 256 KB
s2.txt AC 4 ms 256 KB
s3.txt AC 4 ms 256 KB