Python 本地评测姬

· · 个人记录

洛谷模拟赛使用

3\sim8(阴影行)定义一个 problems 的变量,为一个列表,表示题目列表,每个元素都应为一个元组,依次包含以下内容:

from os import system
from time import time
problems = [ # 题目列表,以下以 https://www.luogu.com.cn/contest/281945 举例
    (1, 'sqrt', 6, {1: 10, 2: 10}),
    (2, 'conversion', 5, {1: 10, 2: 20, 3: 40, 4: 10, 5: 20}),
    (3, 'melody', 6, {1: 10, 2: 45, 3: 10, 4: 10, 5: 10, 6: 15}),
    (4, 'lamplighter', 8, {1: 4, 2: 4, 3: 8, 4: 16, 5: 24, 6: 8, 7: 12, 8: 24})
]
ans = 0
for pid, name, cnt, unskipped in problems:
    print(f'Checking T{pid} ({name}):')
    sc = 0
    for i in range(1, cnt + 1):
        if i not in unskipped:
            print(f'Sample {i}: Skipped')
            continue
        st = time()
        ret = system(f'{name}.exe < {name}\\{name}{i}.in > {name}\\{name}{i}.out')
        t = time() - st
        if t > 1:
            print(f'Sample {i}: TLE {t}s')
        elif ret:
            print(f'Sample {i}: RE (returned {ret}) {t}s')
        elif system(f'fc {name}\\{name}{i}.out {name}\\{name}{i}.ans > log.txt'):
            print(f'Sample {i}: WA {t}s')
        else:
            print(f'Sample {i}: AC {t}s')
            sc += unskipped[i]
    print(f'T{pid} ({name}): {"Un" if sc != 100 else ""}AC {sc}pts\n')
    ans += sc
print(f'All: {ans}')
system('pause')

CSP 模拟赛使用

desktopstr,桌面路径

snamestr,考卷文件夹

data_folderstr,大样例文件夹

problemsList[Tuple[int, int | str, str, int]],题目列表,每道题:(题目顺序,考卷里的题目名称, 大样例的题目名称, 大样例数量)

from os import system
from time import time
desktop = 'C:\\Users\\admin\\Desktop\\'
sname = desktop + # 考生文件夹
data_folder = f'"{desktop}"' # 考卷文件夹
problems = [
    (1, 22840, 'position', 2),
    (2, 19606, 'data', 2),
    (3, 19640, 'number', 2),
    (4, 19636, 'query', 1)
]
for i, pid, name, data_cnt in problems:
    print(f'T{i} || Problem ID: {pid} || Name: {name}')
    if system(f'"C:/Program Files (x86)/Embarcadero/Dev-Cpp/TDM-GCC-64/bin/g++.exe" {sname}\\{pid}\\{pid}.cpp -O2 -std=c++14 -o {desktop}temp.exe'):
        print('Compile Error\n')
        continue
    for j in range(1, data_cnt + 1):
        if system(f'copy {data_folder}\\{name}\\{name}{j}.in {desktop}{name}.in > log.txt'):
            print(f'Test {j}: Unknown Error: Failed in copying input file')
        st = time()
        x = system(f'{desktop}temp.exe')
        t = time() - st
        if x:
            print(f'Test {j}: Runtime Error: Returned {x} ({t}s)')
        elif t > 1:
            print(f'Test {j}: Time Limit Exceeded ({t}s)')
        elif system(f'fc {data_folder}\\{name}\\{name}{j}.ans {name}.out > log.txt'):
            print(f'Test {j}: Wrong Answer ({t}s)')
        else:
            print(f'Test {j}: Accepted ({t}s)')
    print()
system('pause')