結果
| 問題 |
No.122 傾向と対策:門松列(その3)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-11 11:57:33 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 3,918 ms / 5,000 ms |
| コード長 | 1,865 bytes |
| コンパイル時間 | 347 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 11,136 KB |
| 最終ジャッジ日時 | 2024-12-20 11:34:42 |
| 合計ジャッジ時間 | 33,605 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 |
ソースコード
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()