結果
問題 | No.1066 #いろいろな色 / Red and Blue and more various colors (Easy) |
ユーザー |
![]() |
提出日時 | 2020-05-29 23:09:07 |
言語 | Go (1.23.4) |
結果 |
AC
|
実行時間 | 181 ms / 2,000 ms |
コード長 | 2,123 bytes |
コンパイル時間 | 15,202 ms |
コンパイル使用メモリ | 223,000 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-06 07:34:51 |
合計ジャッジ時間 | 16,190 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
package main import ( "bufio" "fmt" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() 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 getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(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 := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 2 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) q := getNextInt(scanner) aa := make([]int, n) for i := 0; i < n; i++ { aa[i] = getNextInt(scanner) } dp := make([]mint, n+1) dp[0] = 1 for i := 0; i < n; i++ { for j := n; j >= 0; j-- { dp[j].mulAs(mint(aa[i] - 1)) if j > 0 { dp[j].addAs(dp[j-1]) } } } for i := 0; i < q; i++ { b := getNextInt(scanner) fmt.Fprintln(writer, dp[b]) } } type mint int64 func (mt mint) mod() mint { m := mint(998244353) mt %= m if mt < 0 { return mt + m } return mt } func (mt mint) add(x mint) mint { return (mt + x).mod() } func (mt mint) mul(x mint) mint { return (mt * x).mod() } func (mt *mint) addAs(x mint) *mint { *mt = mt.add(x) return mt } func (mt *mint) mulAs(x mint) *mint { *mt = mt.mul(x) return mt }