結果
問題 | No.1359 [Zelkova 3rd Tune] 四人セゾン |
ユーザー | aru aru |
提出日時 | 2021-01-23 11:26:04 |
言語 | Go (1.22.1) |
結果 |
AC
|
実行時間 | 423 ms / 2,000 ms |
コード長 | 5,306 bytes |
コンパイル時間 | 13,165 ms |
コンパイル使用メモリ | 201,700 KB |
実行使用メモリ | 9,872 KB |
最終ジャッジ日時 | 2023-08-28 21:22:35 |
合計ジャッジ時間 | 41,060 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,332 KB |
testcase_01 | AC | 3 ms
4,332 KB |
testcase_02 | AC | 2 ms
4,328 KB |
testcase_03 | AC | 262 ms
5,504 KB |
testcase_04 | AC | 175 ms
5,496 KB |
testcase_05 | AC | 162 ms
5,496 KB |
testcase_06 | AC | 367 ms
5,500 KB |
testcase_07 | AC | 246 ms
7,792 KB |
testcase_08 | AC | 243 ms
7,792 KB |
testcase_09 | AC | 65 ms
4,328 KB |
testcase_10 | AC | 65 ms
4,332 KB |
testcase_11 | AC | 313 ms
7,812 KB |
testcase_12 | AC | 312 ms
7,812 KB |
testcase_13 | AC | 198 ms
7,784 KB |
testcase_14 | AC | 199 ms
7,780 KB |
testcase_15 | AC | 175 ms
5,500 KB |
testcase_16 | AC | 173 ms
5,496 KB |
testcase_17 | AC | 335 ms
9,864 KB |
testcase_18 | AC | 333 ms
9,864 KB |
testcase_19 | AC | 286 ms
7,804 KB |
testcase_20 | AC | 292 ms
7,800 KB |
testcase_21 | AC | 423 ms
7,812 KB |
testcase_22 | AC | 313 ms
7,808 KB |
testcase_23 | AC | 209 ms
7,788 KB |
testcase_24 | AC | 225 ms
7,784 KB |
testcase_25 | AC | 34 ms
4,332 KB |
testcase_26 | AC | 32 ms
4,336 KB |
testcase_27 | AC | 108 ms
5,476 KB |
testcase_28 | AC | 148 ms
5,476 KB |
testcase_29 | AC | 131 ms
5,484 KB |
testcase_30 | AC | 167 ms
5,492 KB |
testcase_31 | AC | 206 ms
5,496 KB |
testcase_32 | AC | 176 ms
5,500 KB |
testcase_33 | AC | 135 ms
5,484 KB |
testcase_34 | AC | 131 ms
5,484 KB |
testcase_35 | AC | 219 ms
5,496 KB |
testcase_36 | AC | 174 ms
5,496 KB |
testcase_37 | AC | 35 ms
4,328 KB |
testcase_38 | AC | 34 ms
4,332 KB |
testcase_39 | AC | 30 ms
4,328 KB |
testcase_40 | AC | 28 ms
4,332 KB |
testcase_41 | AC | 91 ms
4,332 KB |
testcase_42 | AC | 60 ms
4,332 KB |
testcase_43 | AC | 50 ms
4,380 KB |
testcase_44 | AC | 345 ms
9,872 KB |
testcase_45 | AC | 138 ms
5,488 KB |
testcase_46 | AC | 45 ms
4,332 KB |
testcase_47 | AC | 234 ms
7,788 KB |
testcase_48 | AC | 218 ms
7,788 KB |
testcase_49 | AC | 220 ms
7,792 KB |
testcase_50 | AC | 166 ms
5,496 KB |
testcase_51 | AC | 9 ms
4,332 KB |
testcase_52 | AC | 294 ms
7,804 KB |
testcase_53 | AC | 340 ms
9,872 KB |
testcase_54 | AC | 352 ms
9,868 KB |
testcase_55 | AC | 349 ms
9,868 KB |
testcase_56 | AC | 352 ms
9,868 KB |
testcase_57 | AC | 353 ms
9,868 KB |
testcase_58 | AC | 350 ms
9,872 KB |
testcase_59 | AC | 349 ms
9,868 KB |
testcase_60 | AC | 344 ms
9,868 KB |
testcase_61 | AC | 328 ms
9,868 KB |
testcase_62 | AC | 347 ms
9,872 KB |
testcase_63 | AC | 349 ms
9,868 KB |
testcase_64 | AC | 351 ms
9,872 KB |
testcase_65 | AC | 347 ms
9,868 KB |
testcase_66 | AC | 345 ms
9,868 KB |
testcase_67 | AC | 356 ms
9,872 KB |
testcase_68 | AC | 343 ms
9,868 KB |
testcase_69 | AC | 325 ms
9,868 KB |
testcase_70 | AC | 322 ms
9,868 KB |
testcase_71 | AC | 316 ms
9,872 KB |
testcase_72 | AC | 352 ms
9,868 KB |
testcase_73 | AC | 344 ms
9,868 KB |
testcase_74 | AC | 340 ms
9,868 KB |
testcase_75 | AC | 344 ms
9,868 KB |
testcase_76 | AC | 337 ms
9,872 KB |
testcase_77 | AC | 342 ms
9,868 KB |
ソースコード
package main import ( "bufio" "fmt" "math" "os" "sort" "strconv" ) var sc = bufio.NewScanner(os.Stdin) var wr = bufio.NewWriter(os.Stdout) func out(x ...interface{}) { fmt.Fprintln(wr, x...) } func getI() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getF() float64 { sc.Scan() i, e := strconv.ParseFloat(sc.Text(), 64) if e != nil { panic(e) } return i } func getInts(N int) []int { ret := make([]int, N) for i := 0; i < N; i++ { ret[i] = getI() } return ret } func getS() string { sc.Scan() return sc.Text() } // min, max, asub, absなど基本関数 func max(a, b int) int { if a > b { return a } return b } func min(a, b int) int { if a < b { return a } return b } // min for n entry func nmin(a ...int) int { ret := a[0] for _, e := range a { ret = min(ret, e) } return ret } // max for n entry func nmax(a ...int) int { ret := a[0] for _, e := range a { ret = max(ret, e) } return ret } func asub(a, b int) int { if a > b { return a - b } return b - a } func abs(a int) int { if a >= 0 { return a } return -a } func lowerBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] >= x }) return idx } func upperBound(a []int, x int) int { idx := sort.Search(len(a), func(i int) bool { return a[i] > x }) return idx } //---------------------------------------- // modint //---------------------------------------- type modint struct { mod int fracMemo []int ifracMemo []int } func newModint(m int) *modint { var ret modint ret.mod = m ret.fracMemo = []int{1, 1} ret.ifracMemo = []int{1, 1} return &ret } func (m *modint) add(a, b int) int { ret := (a + b) % m.mod if ret < 0 { ret += m.mod } return ret } func (m *modint) sub(a, b int) int { ret := (a - b) % m.mod if ret < 0 { ret += m.mod } return ret } func (m *modint) mul(a, b int) int { ret := a * b % m.mod if ret < 0 { ret += m.mod } return ret } func (m *modint) div(a, b int) int { ret := a * m.modinv(b) ret %= m.mod return ret } func (m *modint) pow(p, n int) int { ret := 1 x := p for n != 0 { if n%2 == 1 { ret *= x ret %= m.mod } n /= 2 x = x * x % m.mod } return ret } // 逆元を使った割り算(MOD) // mod. m での a の逆元 a^{-1} を計算する // func (m *modint) modinv(a int) int { // b := m.mod // u := 1 // v := 0 // for b != 0 { // t := a / b // a -= t * b // a, b = b, a // u -= t * v // u, v = v, u // } // u %= m.mod // if u < 0 { // u += m.mod // } // return u // } // 拡張オイラーの互除法で逆元を求める func (mm *modint) modinv(a int) int { m := mm.mod b, u, v := m, 1, 0 for b != 0 { t := a / b a -= t * b a, b = b, a u -= t * v u, v = v, u } u %= m if u < 0 { u += m } return u } //----------------------------------------------- // 行列累乗 // A[][]のp乗を求める //----------------------------------------------- func (m *modint) powModMatrix(A [][]int, p int) [][]int { N := len(A) ret := make([][]int, N) for i := 0; i < N; i++ { ret[i] = make([]int, N) ret[i][i] = 1 } for p > 0 { if p&1 == 1 { ret = m.mulMod(ret, A) } A = m.mulMod(A, A) p >>= 1 } return ret } func (m *modint) mulMod(A, B [][]int) [][]int { H := len(A) W := len(B[0]) K := len(A[0]) C := make([][]int, W) for i := 0; i < W; i++ { C[i] = make([]int, W) } for i := 0; i < H; i++ { for j := 0; j < W; j++ { for k := 0; k < K; k++ { C[i][j] += A[i][k] * B[k][j] C[i][j] %= m.mod } } } return C } //--------------------------------------------------- // nCk 計算関連: TELすることがあるかも // ※pow(x, p-2)を何度も取るので // 厳しそうな場合は、ここを削除して高速なのを使う //--------------------------------------------------- func (m *modint) mfrac(n int) int { if len(m.fracMemo) > n { return m.fracMemo[n] } if len(m.fracMemo) == 0 { m.fracMemo = append(m.fracMemo, 1) } for len(m.fracMemo) <= n { size := len(m.fracMemo) m.fracMemo = append(m.fracMemo, m.fracMemo[size-1]*size%m.mod) } return m.fracMemo[n] } func (m *modint) mifrac(n int) int { if len(m.ifracMemo) > n { return m.ifracMemo[n] } if len(m.ifracMemo) == 0 { m.fracMemo = append(m.ifracMemo, 1) } for len(m.ifracMemo) <= n { size := len(m.ifracMemo) m.ifracMemo = append(m.ifracMemo, m.ifracMemo[size-1]*m.pow(size, m.mod-2)%m.mod) } return m.ifracMemo[n] } func (m *modint) nCr(n, r int) int { if n == r { return 1 } if n < r || r < 0 { return 0 } ret := 1 ret *= m.mfrac(n) ret %= m.mod ret *= m.mifrac(r) ret %= m.mod ret *= m.mifrac(n - r) ret %= m.mod return (ret) } func main() { defer wr.Flush() sc.Split(bufio.ScanWords) sc.Buffer([]byte{}, math.MaxInt32) // this template is new version. // use getI(), getS(), getInts(), getF() N, K, M := getI(), getI(), getI() p := getInts(N) e := getInts(N) a := getInts(N) h := getInts(N) sort.Ints(p) sort.Ints(e) sort.Ints(a) sort.Ints(h) mod := newModint(M) tot := 0 for i := 0; i < N; i++ { ma := nmax(p[i], e[i], a[i], h[i]) mi := nmin(p[i], e[i], a[i], h[i]) d := mod.sub(ma, mi) tot = mod.add(tot, mod.pow(d, K)) } out(tot) }