結果

問題 No.355 数当てゲーム(2)
ユーザー yukirin
提出日時 2016-04-02 15:00:18
言語 Go
(1.23.4)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,517 bytes
コンパイル時間 12,888 ms
コンパイル使用メモリ 237,600 KB
実行使用メモリ 25,616 KB
平均クエリ数 43.69
最終ジャッジ日時 2024-07-16 09:37:42
合計ジャッジ時間 15,648 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 50 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
var sc = bufio.NewScanner(os.Stdin)
func main() {
sc.Split(bufio.ScanWords)
ns, c1, c2 := first()
ans, count, all := make([]int, 0, 4), 0, false
for j := 0; count < 2 && j < 5; j++ {
for i := 0; i < 10; i++ {
if check(ns, i) {
continue
}
tmp := ns[j]
ns[j] = i
x, y := inOut(ns)
ns[j] = tmp
if c1+c2 > x+y {
count++
ans = append(ans, tmp)
break
}
}
}
candi := make([]int, 0, 8)
for i := 0; i < 10; i++ {
if ans[0] == i || ans[1] == i {
continue
}
candi = append(candi, i)
}
ans = ans[:4]
found := false
comb(candi, 2, func(nums []int) {
if all || found {
return
}
copy(ans[2:4], nums)
x, y := inOut(ans)
if x == 4 {
found = true
}
if x+y == 4 {
all = true
}
})
perm(ans, 4, func(nums []int) {
if found {
return
}
x, _ := inOut(nums)
if x == 4 {
found = true
}
})
}
func check(ns []int, n int) bool {
for _, v := range ns {
if n == v {
return true
}
}
return false
}
func first() ([]int, int, int) {
nss := [][]int{
{0, 1, 2, 3}, {4, 5, 6, 7}, {6, 7, 8, 9},
}
for _, v := range nss {
x, y := inOut(v)
if x+y >= 2 {
return v, x, y
}
}
return nil, 0, 0
}
func inOut(ns []int) (int, int) {
fmt.Println(ns[0], ns[1], ns[2], ns[3])
os.Stdout.Sync()
return nextInt(), nextInt()
}
func nextLine() string {
sc.Scan()
return sc.Text()
}
func nextInt() int {
i, _ := strconv.Atoi(nextLine())
return i
}
func nextInt64() int64 {
i, _ := strconv.ParseInt(nextLine(), 10, 64)
return i
}
func nextUint64() uint64 {
i, _ := strconv.ParseUint(nextLine(), 10, 64)
return i
}
func nextFloat() float64 {
f, _ := strconv.ParseFloat(nextLine(), 64)
return f
}
func comb(a []int, r int, fn func([]int)) {
if r > len(a) || r < 1 {
return
}
var f func([]int, int, int)
f = func(ret []int, last, c int) {
if c == 0 {
fn(ret)
return
}
c--
for i, v := range a[last : len(a)-c] {
ret[r-c-1] = v
f(ret, i+last+1, c)
}
}
ret := make([]int, r)
f(ret, 0, r)
}
func perm(a []int, r int, fn func([]int)) {
permL := make([]int, r)
f := func(s []int) {
copy(permL, s)
k := 1
c := make([]int, r+1)
for i := 1; i < len(c); i++ {
c[i] = i
}
for k < r {
i := 0
if k&1 == 1 {
i = c[k]
}
permL[k], permL[i] = permL[i], permL[k]
fn(permL)
for k = 1; c[k] == 0; k++ {
c[k] = k
}
c[k]--
}
}
if r < 2 {
comb(a, r, fn)
return
}
comb(a, r, f)
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0