ЛШ 2019 Б: День 7: Подготовка к олимпиаде / std.sql.check_unordered

ru en cn

с начала прошло: 1940 д. 10:21
страница обновлена: 23.11.2024 20:54

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)
Дальневосточный федеральный университет