結果
問題 | No.122 傾向と対策:門松列(その3) |
ユーザー | 👑 cologne |
提出日時 | 2022-02-11 11:57:33 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 2,907 ms / 5,000 ms |
コード長 | 1,865 bytes |
コンパイル時間 | 186 ms |
コンパイル使用メモリ | 11,116 KB |
実行使用メモリ | 8,696 KB |
最終ジャッジ日時 | 2023-09-09 12:56:48 |
合計ジャッジ時間 | 24,738 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,634 ms
8,696 KB |
testcase_01 | AC | 2,700 ms
8,556 KB |
testcase_02 | AC | 2,907 ms
8,508 KB |
testcase_03 | AC | 2,410 ms
8,668 KB |
testcase_04 | AC | 2,726 ms
8,524 KB |
testcase_05 | AC | 2,871 ms
8,648 KB |
testcase_06 | AC | 2,757 ms
8,672 KB |
testcase_07 | AC | 2,350 ms
8,644 KB |
ソースコード
from math import inf def main(): x = [tuple(map(int, input().split())) for i in range(7)] totmin, totmax = min(a for a, _ in x), max(b for _, b in x) def isect(*a): f, s = zip(*a) return (max(f), min(s)) def cnt(a): x, y = a return max(0, y-x+1) def solve3(a, b, c): ans = cnt(a) * cnt(b) * cnt(c) ans -= cnt(isect(a, b)) * cnt(c) ans -= cnt(isect(a, c)) * cnt(b) ans -= cnt(isect(b, c)) * cnt(a) ans += 2 * cnt(isect(a, b, c)) return ans def solve4(a, b, c, d): ans = cnt(a) * cnt(b) * cnt(c) * cnt(d) ans -= cnt(isect(a, b)) * cnt(c) * cnt(d) ans -= cnt(isect(a, c)) * cnt(b) * cnt(d) ans -= cnt(isect(a, d)) * cnt(b) * cnt(c) ans -= cnt(isect(b, c)) * cnt(a) * cnt(d) ans -= cnt(isect(b, d)) * cnt(a) * cnt(c) ans -= cnt(isect(c, d)) * cnt(a) * cnt(b) ans += 2 * cnt(isect(a, b, c)) * cnt(d) ans += 2 * cnt(isect(a, b, d)) * cnt(c) ans += 2 * cnt(isect(a, c, d)) * cnt(b) ans += 2 * cnt(isect(b, c, d)) * cnt(a) ans += cnt(isect(a, b)) * cnt(isect(c, d)) ans += cnt(isect(a, c)) * cnt(isect(b, d)) ans += cnt(isect(a, d)) * cnt(isect(b, c)) ans -= 6 * cnt(isect(a, b, c, d)) return ans ans = 0 for i in range(totmin, totmax+1): ans += (solve4(*[isect(rng, (-inf, i)) for rng in x[0::2]]) - solve4(*[isect(rng, (-inf, i-1)) for rng in x[0::2]])) * \ solve3(*[isect(rng, (i+1, inf)) for rng in x[1::2]]) ans += solve3(*[isect(rng, (-inf, i)) for rng in x[1::2]]) * \ (solve4(*[isect(rng, (i+1, inf)) for rng in x[0::2]]) - solve4(*[isect(rng, (i+2, inf)) for rng in x[0::2]])) print(ans % (10**9 + 7)) if __name__ == '__main__': main()