{% extends "base.html" %} {% block body %} <style> article { padding: 2.5em 3.5em; font-size: 1.1em; } .code2 { color: #333333; background-color: #f7f7f7; font-family: Consolas; line-height: 1.45; } .code2 { padding: 1em; } li { padding: 0.2em; } </style> <script> </script> <article id="py"> <h2>1. Custom checker (PY)</h2> <hr> <p> Đây là checker mặc định của website, cho phép người dùng cập nhật được nhiều thông tin nhất (chi tiết xem ở bên dưới). Chúng ta cần hoàn thành hàm check dưới đây: </p> <pre class="code2"> def check(process_output, judge_output, **kwargs): # return True/False</pre> <p> Trong đó, <code>**kwargs</code> có thể chứa các biến sau: </p> <ul> <li><code>process_output:</code> output</li> <li><code>judge_output:</code> đáp án</li> <li><code>submission_source</code>: Code bài nộp</li> <li><code>judge_input</code>: input</li> <li><code>point_value:</code> điểm của test đang chấm</li> <li><code>case_position:</code> thứ tự của test</li> <li><code>submission_language:</code> ngôn ngữ của bài nộp</li> <li><code>execution_time:</code> thời gian chạy</li> </ul> <h2>Return: </h2> <ol> <li>Cách 1: Trả về True/False</li> <li>Cách 2: Trả về một object <code>CheckerResult</code> có thể được gọi như sau <pre class="code2">CheckerResult(case_passed_bool, points_awarded, feedback='')</pre></li> </ol> <h2>Ví dụ: </h2> <p>Dưới đây là ví dụ cho bài toán: Input gồm 1 số nguyên n. In ra 2 số nguyên a, b sao cho a + b = n. </p> <pre class="code2"> from dmoj.result import CheckerResult def wa(feedback): return CheckerResult(False, 0, feedback) def check(process_output, judge_output, judge_input, **kwargs): # process the input input_arr = judge_input.split() assert(len(input_arr) == 1) n = int(input_arr[0]) # process the contestant's output output_arr = process_output.split() if (len(output_arr) != 2): return wa('Wrong output format') try: a, b = int(output_arr[0]), int(output_arr[1]) except: return wa('Wrong output format') if (n == a + b): return True return wa('a + b != n')</pre> </article> <article id="cpp"> <h2>2. Custom validator (CPP)</h2> <hr> <p> Để sử dụng chức năng này, cần viết một chương trình C++ pass vào 3 arguments theo thứ tự <code>input_file</code>, <code>output_file</code>, <code>ans_file</code> tương ứng với các file input, output, đáp án. </p> <p> Để test chương trình trên máy tính, có thể dùng lệnh như sau (Windows): <pre class="code2"> main.exe [input_file] [output_file] [ans_file]</pre> hoặc thay bằng <code>./main</code> trên Linux/MacOS. </p> <h2>Return: </h2> <p> Chương trình trả về giá trị 0 nếu AC, 1 nếu WA. Những thông tin được viết ra stdout (bằng cout) sẽ được in ra màn hình cho người nộp bài(feedback) </p> <h2>Ví dụ: </h2> <pre class="code2"> #include <bits/stdc++.h> using namespace std; int main(int argc, char** argv) { ifstream inp(argv[1]); ifstream out(argv[2]); ifstream ans(argv[3]); int n, a, b, c, d; inp >> n; out >> a >> b; ans >> c >> d; if (a + b == c + d) { cout << a << " + " << b << " = " << c << " + " << d << endl; return 0; // AC } else { cout << "a + b = " << a + b << " != " << n << endl; return 1; // WA } } </pre> </article> {% endblock body %}