Submission #11422904


Source Code Expand

# A - 1D Matching
def calculate_cables_length(x: int, y: int, total: int) -> tuple:
    MOD = 10 ** 9 + 7
    if y:
        total = (total * y) % MOD
        y -= 1
    else:
        x += 1
    return x, y, total


def main():
    # sort A, B and the lines between A, B shouldn't cross
    # cross <-> not min distance
    N, *AB = map(int, open(0))
    C = [(i, 1) for i in AB[:N]] + [(i, 0) for i in AB[N:]]
    C.sort()
    ans, a, b = 1, 0, 0
    for i, t in C:
        if t:  # laptop
            a, b, ans = calculate_cables_length(a, b, ans)
        else:  # power sources
            b, a, ans = calculate_cables_length(b, a, ans)
    print(ans)


if __name__ == "__main__":
    main()

Submission Info

Submission Time
Task A - 1D Matching
User solzard
Language Python (3.4.3)
Score 500
Code Size 722 Byte
Status AC
Exec Time 347 ms
Memory 27784 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 14
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 202 ms 17848 KB
001.txt AC 76 ms 8300 KB
002.txt AC 102 ms 10408 KB
003.txt AC 113 ms 11276 KB
004.txt AC 298 ms 25936 KB
005.txt AC 336 ms 27784 KB
006.txt AC 341 ms 27776 KB
007.txt AC 347 ms 27772 KB
008.txt AC 340 ms 27780 KB
009.txt AC 343 ms 27784 KB
010.txt AC 318 ms 27784 KB
011.txt AC 336 ms 27776 KB
example0.txt AC 17 ms 3064 KB
example1.txt AC 17 ms 3064 KB