結果

問題 No.2 素因数ゲーム
ユーザー drymousedrymouse
提出日時 2024-02-12 19:36:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,143 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 84,652 KB
実行使用メモリ 10,260 KB
最終ジャッジ日時 2024-02-12 19:36:33
合計ジャッジ時間 8,247 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 192 ms
6,676 KB
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

#define length(array) (sizeof(array) / sizeof(array[0]))

int priming(int N, int primes[], int times[]) {
    int ps[N / 2 + 1];
    ps[0] = 2;
    int index = 1;
    bool flag = false;
    for (int i = 3; i < N + 1; i += 2) {
        for (int j = 0; j < index; j++) {
            if (i % ps[j] == 0) {
                flag = true;
                break;
            }
        }
        if (flag) {
            flag = false;
            continue;
        }
        ps[index] = i;
        index++;
    }

    int index2 = 0;
    for (int i = 0; i < index; i++) {
        if (N % ps[i] == 0) {
            int shou = N;
            primes[index2] = ps[i];
            times[index2] = 0;
            for (;shou % ps[i] == 0;) {
                times[index2]++;
                shou /= ps[i];
            }
            index2++;
        }
    }

    return index2;
}

void printints(int list[], int l) {
    cout << "[";
    for (int i = 0; i < l; i++) {
        cout << list[i] << ", ";
    }
    cout << "]" << endl;
}

void copy(int moto[], int saki[], int l) {
    for (int i = 0; i < l; i++) {
        saki[i] = moto[i];
    }
}

int judge(int times[], int l, int depth) {
    if (depth < 0) {return 100;}
    int sum = 0;
    for (int i = 0; i < l; i++) {
        sum += times[i];
    }
    if (sum == 0) {return -1;}
    int saizen = -1;
    for (int i = 0; i < l; i++) {
        int next[l];
        copy(times, next, l);
        for (int j = 0; j < times[i]; j++) {
            next[i] = j;
            saizen = max(saizen, -judge(next, l, depth + 1));
        }
    }
    //cout << "winner: " << saizen << " at ";
    //printints(times, l);
    return saizen;
}

int main(void) {
    int N;
    cin >> N;
    int primes[int(sqrt(N))];
    int times[int(sqrt(N))];
    int l = priming(N, primes, times);
    /*printints(primes, l);
    printints(times, l);*/
    //cout << judge(times, l, 0) << endl;
    int result = judge(times, l, 0);
    if (result == 1) {
        cout << "Alice" << endl;
    } else {
        cout << "Bob" << endl;
    }
    return 0;
}
0