feat(problem/remote): add luogu

This commit is contained in:
Baoshuo Ren 2023-02-02 21:53:36 +08:00
parent 7cdb39267a
commit dcbe7691a2
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 76 additions and 0 deletions

View File

@ -51,6 +51,16 @@ $new_remote_problem_form->addInput('remote_problem_id', [
$vdata['remote_problem_id'] = $id; $vdata['remote_problem_id'] = $id;
return '';
} else if ($remote_oj === 'luogu') {
$id = trim(strtoupper($id));
if (!validateLuoguProblemId($id)) {
return '不合法的题目 ID';
}
$vdata['remote_problem_id'] = $id;
return ''; return '';
} }

View File

@ -176,6 +176,7 @@ function newSubmissionForm($form_name, $requirement, $zip_file_name_gen, $handle
$content['config'][] = ["{$req['name']}_language", $_POST["{$form_name}_{$req['name']}_language"]]; $content['config'][] = ["{$req['name']}_language", $_POST["{$form_name}_{$req['name']}_language"]];
} else if ($req['type'] == "remote submission") { } else if ($req['type'] == "remote submission") {
$content['no_rejudge'] = true; $content['no_rejudge'] = true;
$content['manual_submit'] = true;
if ($req['name'] == "luogu") { if ($req['name'] == "luogu") {
$content['config'][] = ["{$req['name']}_uid", $_POST["{$form_name}_{$req['name']}_uid"]]; $content['config'][] = ["{$req['name']}_uid", $_POST["{$form_name}_{$req['name']}_uid"]];

View File

@ -79,3 +79,7 @@ function is_short_string($str) {
function validateCodeforcesProblemId($str) { function validateCodeforcesProblemId($str) {
return preg_match('/(|GYM)[1-9][0-9]{0,5}[A-Z][1-9]?/', $str) !== true; return preg_match('/(|GYM)[1-9][0-9]{0,5}[A-Z][1-9]?/', $str) !== true;
} }
function validateLuoguProblemId($str) {
return preg_match('/P[1-9][0-9]{4,5}/', $str) !== true;
}

View File

@ -96,6 +96,10 @@ class UOJRemoteProblem {
return static::$providers['loj']['url'] . '/p/' . $id; return static::$providers['loj']['url'] . '/p/' . $id;
} }
static function getLuoguProblemUrl($id) {
return static::$providers['luogu']['url'] . '/problem/' . $id;
}
static function getCodeforcesProblemBasicInfoFromHtml($id, $html) { static function getCodeforcesProblemBasicInfoFromHtml($id, $html) {
$remote_provider = static::$providers['codeforces']; $remote_provider = static::$providers['codeforces'];
@ -400,6 +404,59 @@ class UOJRemoteProblem {
]; ];
} }
static function getLuoguProblemBasicInfo($id) {
$remote_provider = static::$providers['luogu'];
$res = static::curl_get(static::getLuoguProblemUrl($id) . '?_contentOnly=1');
if (!$res) return null;
// Convert stdClass to array
$res = json_decode(json_encode($res['response']), true);
if (!isset($res['code']) || $res['code'] != 200) return null;
$problem = $res['currentData']['problem'];
$statement = '';
if ($problem['background']) {
$statement .= "\n### 题目背景\n\n";
$statement .= $problem['background'] . "\n";
}
$statement .= "\n### 题目描述\n\n";
$statement .= $problem['description'] . "\n";
$statement .= "\n### 输入格式\n\n";
$statement .= $problem['inputFormat'] . "\n";
$statement .= "\n### 输出格式\n\n";
$statement .= $problem['outputFormat'] . "\n";
$statement .= "\n### 输入输出样例\n\n";
foreach ($problem['samples'] as $id => $sample) {
$display_sample_id = $id + 1;
$statement .= "\n#### 样例输入 #{$display_sample_id}\n\n";
$statement .= "\n```text\n{$sample[0]}\n```\n\n";
$statement .= "\n#### 样例输出 #{$display_sample_id}\n\n";
$statement .= "\n```text\n{$sample[1]}\n```\n\n";
}
$statement .= "\n### 说明/提示\n\n";
$statement .= $problem['hint'] . "\n";
return [
'type' => 'html',
'title' => "{$remote_provider['short_name']}{$problem['pid']}{$problem['title']}",
'time_limit' => (float)max($problem['limits']['time']) / 1000.0,
'memory_limit' => (float)max($problem['limits']['memory']) / 1024.0,
'difficulty' => -1,
'statement' => HTML::parsedown()->text($statement),
];
}
public static function getSubmissionRequirements($oj) { public static function getSubmissionRequirements($oj) {
$remote_provider = UOJRemoteProblem::$providers[$oj]; $remote_provider = UOJRemoteProblem::$providers[$oj];
@ -431,6 +488,8 @@ class UOJRemoteProblem {
return static::getUojProblemUrl($id); return static::getUojProblemUrl($id);
} else if ($oj === 'loj') { } else if ($oj === 'loj') {
return static::getLojProblemUrl($id); return static::getLojProblemUrl($id);
} else if ($oj === 'luogu') {
return static::getLuoguProblemUrl($id);
} }
return null; return null;
@ -446,6 +505,8 @@ class UOJRemoteProblem {
return static::getUojProblemBasicInfo($id); return static::getUojProblemBasicInfo($id);
} else if ($oj === 'loj') { } else if ($oj === 'loj') {
return static::getLojProblemBasicInfo($id); return static::getLojProblemBasicInfo($id);
} else if ($oj === 'luogu') {
return static::getLuoguProblemBasicInfo($id);
} }
return null; return null;