結果
問題 | No.12 限定された素数 |
ユーザー | aru aru |
提出日時 | 2020-06-28 12:07:26 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 190 ms / 5,000 ms |
コード長 | 1,837 bytes |
コンパイル時間 | 11,232 ms |
コンパイル使用メモリ | 210,424 KB |
実行使用メモリ | 66,084 KB |
最終ジャッジ日時 | 2023-09-21 17:45:19 |
合計ジャッジ時間 | 17,222 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 170 ms
66,080 KB |
testcase_01 | AC | 180 ms
66,080 KB |
testcase_02 | AC | 181 ms
66,084 KB |
testcase_03 | AC | 169 ms
66,080 KB |
testcase_04 | AC | 167 ms
66,080 KB |
testcase_05 | AC | 176 ms
66,084 KB |
testcase_06 | AC | 173 ms
66,084 KB |
testcase_07 | AC | 187 ms
66,080 KB |
testcase_08 | AC | 184 ms
66,080 KB |
testcase_09 | AC | 173 ms
66,080 KB |
testcase_10 | AC | 176 ms
66,080 KB |
testcase_11 | AC | 183 ms
66,080 KB |
testcase_12 | AC | 186 ms
66,084 KB |
testcase_13 | AC | 181 ms
66,084 KB |
testcase_14 | AC | 190 ms
66,080 KB |
testcase_15 | AC | 182 ms
66,084 KB |
testcase_16 | AC | 178 ms
66,080 KB |
testcase_17 | AC | 178 ms
66,080 KB |
testcase_18 | AC | 164 ms
66,080 KB |
testcase_19 | AC | 158 ms
66,084 KB |
testcase_20 | AC | 161 ms
66,080 KB |
testcase_21 | AC | 180 ms
66,080 KB |
testcase_22 | AC | 175 ms
66,080 KB |
testcase_23 | AC | 171 ms
66,080 KB |
testcase_24 | AC | 171 ms
66,084 KB |
testcase_25 | AC | 171 ms
66,080 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) func out(x ...interface{}) { fmt.Println(x...) } var sc = bufio.NewScanner(os.Stdin) func getInt() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getInts(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { ret[i] = getInt() } return ret } func getString() string { sc.Scan() return sc.Text() } // min, max, asub, absなど基本関数 func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } func asub(a, b int) int { if a > b { return a - b } return b - a } func abs(a int) int { if a >= 0 { return a } return -a } func lowerBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] >= x }) return idx } func upperBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] > x }) return idx } func prime(x int) []int { d := make([]int, x+1) ret := make([]int, 0) for i := 2; i <= x; i++ { if d[i] == 0 { ret = append(ret, i) for j := i; j <= x; j += i { d[j] = 1 } } } return ret } func main() { sc.Split(bufio.ScanWords) p := prime(5000000) p = append([]int{0}, p...) p = append(p, 5000000) m := make([]int, len(p)) for i, v := range p { for v > 0 { m[i] |= 1 << (v % 10) v /= 10 } } mask := 0 N := getInt() for i := 0; i < N; i++ { mask |= 1 << getInt() } if mask == 1023 { out(4999999) return } ret := -1 for i := 1; i < len(p)-1; i++ { x := 0 for j := 0; j < len(p)-i; j++ { x |= m[i+j] // fmt.Printf("%b %b\n", mask, x) if x&(1023^mask) != 0 { break } if x == mask { // out(i, j, p[i:i+j+1], m[j]) ret = max(ret, p[i+j+1]-p[i-1]-2) } } } out(ret) }