結果

問題 No.6 使いものにならないハッシュ
ユーザー SugihaMSugihaM
提出日時 2020-04-17 18:16:48
言語 Go
(1.22.1)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,289 bytes
コンパイル時間 11,110 ms
コンパイル使用メモリ 204,752 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-14 23:23:33
合計ジャッジ時間 12,327 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"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)
	k, _ := strconv.Atoi(Scanner())
	n, _ := strconv.Atoi(Scanner())
	p := prime(k, n)
	sort.Ints(p)
	h := make([]int, len(p))
	for i, j := range p {
		h[i] = hash(j)
	}
	ans := 0
	l := 0
	for i := 0; i < len(h); i++ {
		box := make(map[int]int)
		box[h[i]] = 1
		for j := i + 1; j < len(h); j++ {
			box[h[j-1]] = 1
			_, flag := box[h[j]]
			if !flag {
				if j-i+1 > l {
					ans = p[i]
					l = j - i + 1
				} else if j-i+1 == l {
					ans = max(ans, p[i])
				}
			} else {
				break
			}
		}
	}
	fmt.Println(ans)
}

func prime(k int, 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] {
			if i >= k {
				prime = append(prime, i)
			}
			for j := 2 * i; j <= n; j += i {
				notprime[j] = true
			}
		}
	}
	return prime
}

func hash(n int) int {
	m := 0
	for i := n; i > 0; i /= 10 {
		m += i % 10
	}
	if m >= 10 {
		return hash(m)
	}
	return m
}

func max(x int, y int) int {
	if x >= y {
		return x
	} else {
		return y
	}
}
0