結果

問題 No.7 プライムナンバーゲーム
ユーザー tsuchinagatsuchinaga
提出日時 2019-04-25 09:39:38
言語 Go
(1.22.1)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 15,631 ms
コンパイル使用メモリ 209,940 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-11 05:15:08
合計ジャッジ時間 16,623 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 3 ms
4,380 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 5 ms
4,384 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 5 ms
4,376 KB
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import "fmt"

func main() {
	var n int
	_, _ = fmt.Scan(&n)

	pn := make([]int, 0)
	pnn := make([]int, n+1)
	for i := 2; i <= n; i++ {
		if pnn[i] == 0 {
			pn = append(pn, i)

			for j := i + i; j <= n; j += i {
				pnn[j] = 1
			}
		}
	}
	// fmt.Println(pn)

	// 1が勝ち、-1が負け、0は未確認
	wl := make([]int, n+1)
	wl[0], wl[1], wl[2], wl[3] = 1, 1, -1, -1
	u := n + 1 - 4 // 未確定数
	t := -1        // 勝ちか負けのどちらを確認するか
	for u > 0 {
		for m, w := range wl {
			if w != t {
				continue
			}

			for _, p := range pn {
				if i := m + p; i < n+1 && wl[i] == 0 {
					wl[i] = w * -1
					u--
				}
			}
		}

		// fmt.Println(u, t, wl)
		t *= -1
	}

	if wl[n] == 1 {
		fmt.Println("Win")
	} else {
		fmt.Println("Lose")
	}
}
0