結果
問題 | No.1084 積の積 |
ユーザー | ccppjsrb |
提出日時 | 2020-10-01 22:34:08 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 68 ms / 2,000 ms |
コード長 | 3,295 bytes |
コンパイル時間 | 13,298 ms |
コンパイル使用メモリ | 231,336 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-07 05:33:50 |
合計ジャッジ時間 | 15,217 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 1 ms
6,816 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 1 ms
6,944 KB |
testcase_04 | AC | 68 ms
6,944 KB |
testcase_05 | AC | 4 ms
6,940 KB |
testcase_06 | AC | 68 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,944 KB |
testcase_09 | AC | 8 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 7 ms
6,944 KB |
testcase_13 | AC | 13 ms
6,944 KB |
testcase_14 | AC | 5 ms
6,940 KB |
testcase_15 | AC | 5 ms
6,940 KB |
testcase_16 | AC | 15 ms
6,940 KB |
testcase_17 | AC | 6 ms
6,944 KB |
testcase_18 | AC | 10 ms
6,940 KB |
testcase_19 | AC | 13 ms
6,944 KB |
testcase_20 | AC | 4 ms
6,940 KB |
testcase_21 | AC | 5 ms
6,940 KB |
testcase_22 | AC | 4 ms
6,940 KB |
testcase_23 | AC | 9 ms
6,940 KB |
testcase_24 | AC | 7 ms
6,944 KB |
testcase_25 | AC | 13 ms
6,944 KB |
testcase_26 | AC | 15 ms
6,948 KB |
testcase_27 | AC | 15 ms
6,944 KB |
testcase_28 | AC | 15 ms
6,940 KB |
testcase_29 | AC | 15 ms
6,940 KB |
testcase_30 | AC | 15 ms
6,940 KB |
testcase_31 | AC | 15 ms
6,940 KB |
ソースコード
package main import ( "bufio" "fmt" "os" "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 extra := 0 if os.Getenv("I") == "IronMan" { fp, _ = os.Open(os.Getenv("END_GAME")) extra = 100 } scanner := bufio.NewScanner(fp) configure(scanner) writer := bufio.NewWriter(wfp) defer func() { r := recover() if r != nil { fmt.Fprintln(writer, r) } writer.Flush() }() solve(scanner, writer) for i := 0; i < extra; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { type mint = Mint n := getNextInt(scanner) aa := make([]mint, n) pp := make([]mint, n+1) zero := false for i := 0; i < n; i++ { aa[i] = mint(getNextInt(scanner)) zero = zero || (aa[i] == 0) } if zero { fmt.Fprintln(writer, 0) return } l := 0 var a mint = 1 imos := make([]mint, n+1) for r := 0; r < n; r++ { a *= aa[r] for l < r && a >= 1000000000 { a /= aa[l] l++ } pp[l]++ pp[r+1]-- imos[r+1] -= mint(r - l + 1) } for i := 0; i < n; i++ { pp[i+1] += pp[i] } for i := 0; i < n+1; i++ { pp[i] += imos[i] } for i := 0; i < n; i++ { pp[i+1] += pp[i] } var ans mint = 1 for i := 0; i < n; i++ { ans.MulAs(aa[i].Pow(pp[i])) } fmt.Fprintln(writer, ans) } // Mod constants. const ( Mod1000000007 = 1000000007 Mod998244353 = 998244353 ) var mod Mint = Mod1000000007 // Mint treats the modular arithmetic type Mint int64 // SetMod sets the mod. It must be called first. func SetMod(newmod Mint) { mod = newmod } // Mod returns m % mod. func (m Mint) Mod() Mint { m %= mod if m < 0 { return m + mod } return m } // Inv returns modular multiplicative inverse func (m Mint) Inv() Mint { return m.Pow(Mint(0).Sub(2)) } // Pow returns m^n func (m Mint) Pow(n Mint) Mint { p := Mint(1) for n > 0 { if n&1 == 1 { p.MulAs(m) } m.MulAs(m) n >>= 1 } return p } // Add returns m+x func (m Mint) Add(x Mint) Mint { return (m + x).Mod() } // Sub returns m-x func (m Mint) Sub(x Mint) Mint { return (m - x).Mod() } // Mul returns m*x func (m Mint) Mul(x Mint) Mint { return (m * x).Mod() } // Div returns m/x func (m Mint) Div(x Mint) Mint { return m.Mul(x.Inv()) } // AddAs assigns *m + x to *m and returns m func (m *Mint) AddAs(x Mint) *Mint { *m = m.Add(x) return m } // SubAs assigns *m - x to *m and returns m func (m *Mint) SubAs(x Mint) *Mint { *m = m.Sub(x) return m } // MulAs assigns *m * x to *m and returns m func (m *Mint) MulAs(x Mint) *Mint { *m = m.Mul(x) return m } // DivAs assigns *m / x to *m and returns m func (m *Mint) DivAs(x Mint) *Mint { *m = m.Div(x) return m }