ЛШ 2017. Олимпиада C, D / std.sql.check_unordered

ru en cn

с начала прошло: 2268 д. 06:59
страница обновлена: 27.09.2023 15:39

std.sql.check_unordered: check_unordered.py

import sys
from json import loads

ERR_OK = 0
ERR_WA = 1
ERR_PE = 2
ERR_UH = 3

with open(sys.argv[3], 'r') as fans, open(sys.argv[2], 'r') as fout:
    eans = int(fans.readline())
    eout = int(fout.readline())

    if eout != ERR_OK: print(fout.read()); exit(eout)

    lans = loads(fans.read())
    lout = loads(fout.read())

    if lout != lans:

        if lout and len(lout[0]) != len(lans[0]):
            print('Incorrect number of columns!')
            exit(ERR_WA)

        if len(lout) > len(lans):
            print('Too many rows in output!')
            exit(ERR_WA)

        if len(lout) < len(lans):
            print('Too few rows in output!')
            exit(ERR_WA)

        #Data checking:
        hans = set(tuple(it) for it in lans)
        hout = set(tuple(it) for it in lout)
        if hout == hans:
            # List is not sorted
            exit(ERR_OK)
        else:
            print('Row mismatch!')
            for rans, rout in zip(sorted(hans - hout), sorted(hout - hans)):
                print('ans:', rans)
                print('out:', rout)
                print()
        exit(ERR_WA)

exit(ERR_OK)
Дальневосточный федеральный университет