結果

問題 No.7 プライムナンバーゲーム
ユーザー SugihaMSugihaM
提出日時 2020-04-17 20:19:56
言語 Go
(1.22.1)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 15,057 ms
コンパイル使用メモリ 233,568 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-04-09 04:51:48
合計ジャッジ時間 11,641 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 100000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	p := prime(n)
	dp := make([]int, n+1)
	dp[0] = 1
	dp[1] = 1
	for i := 2; i < n+1; i++ {
		for _, j := range p {
			if i-j < 0 {
				break
			}
			if dp[i-j] == 0 {
				dp[i] = 1
				break
			}
		}
	}
	ans := "Lose"
	if dp[n] == 1 {
		ans = "Win"
	}
	fmt.Println(ans)
}

func prime(n int) []int {
	notprime := make([]bool, n+1)
	prime := make([]int, 0)
	notprime[0] = true
	notprime[1] = true
	for i := 2; i <= n; i++ {
		if !notprime[i] {
			prime = append(prime, i)
		}
		for j := 2 * i; j <= n; j += i {
			notprime[j] = true
		}
	}
	return prime
}
0