package main import ( "bufio" "fmt" "os" "strconv" ) // https://yukicoder.me/submissions/353490 var isProduct = true func main() { nextReader = newScanner() n := nextInt() m := nextInt() dp := make([][]int64, n) for i := 0; i < n; i++ { dp[i] = make([]int64, n) } // i = i駅 for i := 0; i < m; i++ { a := nextInt64s(n) // j = j両 for j := 0; j < n; j++ { var prev int64 = 0 if i > 0 { prev = dp[i-1][j] } dp[i][j] = prev + a[j] if dp[i][j] == 777 { fmt.Println("YES") return } } } for i := 0; i < m; i++ { // j = j両 debug(i, ": ") for j := 0; j < n; j++ { debug(dp[i][j]) debug(" ") } debugln("") } sums := make([][]int64, m) for i := 0; i < m; i++ { debugln(i, "駅目:") sums[i] = make([]int64, n) for e := 0; e < n; e++ { // 0 ~ e車両までの合計乗客 var sum int64 = dp[i][e] if e > 0 { sum += sums[i][e-1] } sums[i][e] = sum debugln(i, e, sum) } // 計算量 for s := -1; s < n; s++ { for e := s + 1; e < n; e++ { sum := sums[i][e] if s > -1 { sum = sums[i][e] - sums[i][s] } debugf("%d ~ %dの乗客: %d\n", s+1, e, sum) if sum == 777 { fmt.Println("YES") return } } debugln() } } fmt.Println("NO") } func debugln(s ...interface{}) { if !isProduct { fmt.Println(s...) } } func debug(s ...interface{}) { if !isProduct { fmt.Print(s...) } } func debugf(f string, s ...interface{}) { if !isProduct { fmt.Printf(f, s...) } } var nextReader func() string func newScanner() func() string { r := bufio.NewScanner(os.Stdin) r.Buffer(make([]byte, 1024), int(1e+11)) r.Split(bufio.ScanWords) return func() string { r.Scan() return r.Text() } } func nextString() string { return nextReader() } func nextInt64() int64 { v, _ := strconv.ParseInt(nextReader(), 10, 64) return v } func nextInt() int { v, _ := strconv.Atoi(nextReader()) return v } func nextInts(n int) []int { r := make([]int, n) for i := 0; i < n; i++ { r[i] = nextInt() } return r } func nextInt64s(n int) []int64 { r := make([]int64, n) for i := 0; i < n; i++ { r[i] = nextInt64() } return r } func nextFloat64() float64 { f, _ := strconv.ParseFloat(nextReader(), 64) return f } func maxInt(a, b int) int { if a > b { return a } else { return b } }