Created
October 6, 2021 08:03
-
-
Save mocyuto/c14bd873561748e878562991c8bb4c55 to your computer and use it in GitHub Desktop.
しゃくとり法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
var length, max int | |
fmt.Scanf("%d %d", &length, &max) | |
arr := []int{} | |
for i := 0; i < length; i++ { | |
var num int | |
fmt.Scanf("%d", &num) | |
arr = append(arr, num) | |
} | |
fmt.Println(syaku(arr, max)) | |
} | |
func syaku(arr []int, max int) int { | |
longest := 0 | |
for i, n := range arr { | |
tmp := n | |
for j, m := range arr[i:] { | |
if tmp <= max && j >= longest { | |
fmt.Println(longest, j , tmp) | |
longest = j+1 | |
} | |
tmp *= m | |
} | |
} | |
return longest | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment