結果
問題 | No.777 再帰的ケーキ |
ユーザー | ccppjsrb |
提出日時 | 2020-06-05 19:16:34 |
言語 | Go (1.22.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,574 bytes |
コンパイル時間 | 11,517 ms |
コンパイル使用メモリ | 220,968 KB |
実行使用メモリ | 40,584 KB |
最終ジャッジ日時 | 2024-05-09 16:24:06 |
合計ジャッジ時間 | 17,351 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,248 KB |
testcase_02 | AC | 1 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 1 ms
5,376 KB |
testcase_05 | AC | 1 ms
5,376 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | WA | - |
testcase_11 | AC | 1 ms
5,376 KB |
testcase_12 | AC | 1 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 1 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | WA | - |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | WA | - |
testcase_21 | AC | 5 ms
5,376 KB |
testcase_22 | AC | 6 ms
5,376 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 6 ms
5,376 KB |
testcase_26 | AC | 7 ms
5,376 KB |
testcase_27 | WA | - |
testcase_28 | AC | 758 ms
40,448 KB |
testcase_29 | AC | 713 ms
40,584 KB |
testcase_30 | AC | 711 ms
39,992 KB |
testcase_31 | AC | 716 ms
40,448 KB |
testcase_32 | AC | 441 ms
40,448 KB |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 363 ms
40,048 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "sort" "strconv" ) func configure(scanner *bufio.Scanner) { scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) } func getNextString(scanner *bufio.Scanner) string { scanned := scanner.Scan() if !scanned { panic("scan failed") } return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 1 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) cnt = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() for i := 0; i < cnt; i++ { if i > 0 { fmt.Fprintln(writer, "-----------------------------------") } solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) bb := make([]int64, n) cakes := make([]cake, n) counter := map[int64]int{} for i := 0; i < n; i++ { cakes[i].a = getNextInt64(scanner) cakes[i].b = getNextInt64(scanner) cakes[i].c = getNextInt64(scanner) bb[i] = cakes[i].b counter[cakes[i].a]++ } rm := rank(bb) sort.SliceStable(cakes, func(i, j int) bool { return cakes[i].a > cakes[j].a }) dec := newDecomposition(len(rm)) for i := 0; i < n; i++ { r := rm[cakes[i].b] mx := cint(0) a := cakes[i].a c := cakes[i].c i += counter[a] - 1 for counter[a] > 0 { counter[a]-- if r+1 < len(rm) { mx.maxAs(dec.max(r+1, len(rm))) } } dec.maximize(r, int64(mx)+c) } fmt.Fprintln(writer, dec.max(0, len(rm))) } func rank(aa []int64) map[int64]int { m := map[int64]int{} for _, a := range aa { m[a] = 1 } rr := make([]int64, 0) for a := range m { rr = append(rr, a) } sort.SliceStable(rr, func(i, j int) bool { return rr[i] < rr[j] }) res := map[int64]int{} for i := 0; i < len(rr); i++ { res[rr[i]] = i } return res } type cake struct { a, b, c int64 } type decomposition struct { chunk int bucket [][]int64 } func newDecomposition(n int) decomposition { bucket := make([][]int64, 1) bucket[0] = make([]int64, n) chunk := 8 for i := 0; n > 1; i++ { n = (n-1)/chunk + 1 bucket = append(bucket, make([]int64, n)) } return decomposition{ chunk: chunk, bucket: bucket, } } func (dec *decomposition) upleft(l int) int { return (l + dec.chunk - 1) / dec.chunk } func (dec *decomposition) upright(r int) int { return r / dec.chunk } func (dec *decomposition) maximize(index int, value int64) { dec.bucket[0][index] = value h := len(dec.bucket) for i := 0; i < h-1; i++ { p := index / dec.chunk r := (p + 1) * dec.chunk if r >= len(dec.bucket[i]) { r = len(dec.bucket[i]) } dec.bucket[i+1][p] = value for j := p * dec.chunk; j < r; j++ { if dec.bucket[i+1][p] < dec.bucket[i][j] { dec.bucket[i+1][p] = dec.bucket[i][j] } } index /= dec.chunk } } func (dec *decomposition) max(l, r int) int64 { return dec.maxh(l, r, 0) } func (dec *decomposition) maxh(l, r, h int) int64 { m := dec.bucket[h][l] ll := dec.upleft(l) rr := dec.upright(r) for i := l; i < r && i < ll*dec.chunk; i++ { if m < dec.bucket[h][i] { m = dec.bucket[h][i] } } if ll < rr { mm := dec.maxh(ll, rr, h+1) if m < mm { m = mm } } for i := rr * dec.chunk; i < r && ll <= rr; i++ { if m < dec.bucket[h][i] { m = dec.bucket[h][i] } } return m } type cint int64 func (ct *cint) cintize(x interface{}) cint { if y, isCint := x.(cint); isCint { return y } if y, isInt64 := x.(int64); isInt64 { return cint(y) } return cint(x.(int)) } func (ct *cint) minAs(x interface{}) *cint { *ct = ct.min(x) return ct } func (ct *cint) maxAs(x interface{}) *cint { *ct = ct.max(x) return ct } func (ct cint) min(x interface{}) cint { y := ct.cintize(x) if ct > y { return y } return ct } func (ct cint) max(x interface{}) cint { y := ct.cintize(x) if ct < y { return y } return ct } func (ct cint) add(x interface{}) cint { return ct + ct.cintize(x) } func (ct cint) sub(x interface{}) cint { return ct - ct.cintize(x) } func (ct cint) mul(x interface{}) cint { return ct * ct.cintize(x) } func (ct cint) div(x interface{}) cint { return ct / ct.cintize(x) }