結果

問題 No.2 素因数ゲーム
コンテスト
ユーザー Onju
提出日時 2015-02-11 16:23:51
言語 C++11(old_compat)
(gcc 12.4.0 + boost 1.89.0)
コンパイル:
g++-12 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -include bits/stdc++.h -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1,187 ms / 5,000 ms
コード長 1,542 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,458 ms
コンパイル使用メモリ 173,100 KB
実行使用メモリ 134,640 KB
最終ジャッジ日時 2026-03-08 16:01:45
合計ジャッジ時間 17,338 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <climits>
#include <functional>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdlib>
#define N_MAX 100000000
#define P_SIZE 30	//高々26・・のはず

using namespace std;

vector<int>* getPrime(int N)
{
	auto list = new bool[N + 1];
	auto prime = new vector<int>();
	int sn = (int)sqrt(N);

	list[0] = list[1] = false;
	for (int i = 2; i <= N; ++i)
		list[i] = true;

	for (int i = 2; i <= sn; ++i)
	{
		if (list[i])
		{
			int jmax = N / i;
			for (int j = i; j <= jmax; ++j)
				list[i*j] = false;
		}
	}

	for (int i = 2; i <= N; ++i)
	{
		if (list[i])
			prime->push_back(i);
	}

	delete[] list;

	return prime;
}

bool DP(char x[], int n)
{
	switch (n)
	{
	case 0:
		return false;
	case 1:
		return true;
	}

	bool ans = false;

	for (int i = 0; !ans && i < n; ++i)
	{
		for (int j = 1; !ans && j <= x[i]; ++j)
		{
			x[i] -= j;
			if (!x[i])
			{
				swap(x[i], x[n-1]);
				ans = !DP(x, n - 1);
				swap(x[i], x[n-1]);
			}
			else
				ans = !DP(x, n);
			x[i] += j;
		}
	}

	return ans;
}

int main()
{
	char name[][6] = { "Alice", "Bob" };
	int N, Pnum=0, Psize=0;
	char P[P_SIZE];
	memset(P, 0, sizeof(char)*P_SIZE);

	cin >> N;

	auto prime = getPrime(N);
	int temp = 0, pn = -1;
	for (auto it = prime->begin(); it != prime->end(); ++it)
	{
		while (!(N%(*it)))
		{
			if (*it != temp)
			{
				temp = *it;
				++pn;
			}
			N /= (*it);
			++P[pn];
		}
	}
	sort(P, P + P_SIZE, greater<char>());

	cout << name[DP(P, strlen(P)) ? 0 : 1] << endl;

	delete prime;

	return 0;
}
0