from __future__ import annotations from enum import Enum from typing import Any, Dict, List, Optional from pydantic import BaseModel, Field, model_validator class JudgeStatus(str, Enum): AC = "Accepted" WA = "Wrong Answer" TLE = "Time Limit Exceeded" MLE = "Memory Limit Exceeded" RE = "Runtime Error" CE = "Compile Error" SEC = "Security Violation" class CaseResult(BaseModel): case_id: int case_name: str = "" passed: bool time_ms: float = 0.0 message: Optional[str] = None error_type: Optional[str] = None user_output_summary: Optional[str] = None expected_summary: Optional[str] = None max_diff: Optional[float] = None input_summary: Optional[str] = None stdout: Optional[str] = None class JudgeResult(BaseModel): status: JudgeStatus message: str passed_count: int = 0 total_count: int = 0 execution_time_ms: float = 0.0 peak_memory_mb: float = 0.0 beats_runtime_pct: Optional[float] = None beats_memory_pct: Optional[float] = None cases: List[CaseResult] = Field(default_factory=list) stdout: Optional[str] = None error_detail: Optional[str] = None # Backward compatibility properties @property def passed_cases(self) -> int: return self.passed_count @property def total_cases(self) -> int: return self.total_count @property def runtime_ms(self) -> float: return self.execution_time_ms class ProblemMeta(BaseModel): slug: str title: str difficulty: str = "Medium" # Easy / Medium / Hard category: str = "Attention" # Attention / ML / DL / RL / Pytorch / AIInfra tags: List[str] = Field(default_factory=list) description_md: str entry_point: str # Function or class name to evaluate starter_code: str reference_code: str forbidden_modules: List[str] = Field(default_factory=list) forbidden_calls: List[str] = Field(default_factory=list) time_limit: float = 5.0 memory_limit_mb: int = 512 atol: float = 1e-4 rtol: float = 1e-4 test_code: str = "" # Standalone test runner code or generator is_featured: bool = False editorial_md: Optional[str] = None class SubmissionRequest(BaseModel): problem_slug: str = Field(..., max_length=128) code: str = Field(..., max_length=65536) is_test: bool = False custom_testcase: Optional[str] = Field(None, max_length=16384) language: str = Field("python", max_length=32) @model_validator(mode="after") def custom_cases_are_only_for_self_tests(self): if not self.is_test and self.custom_testcase and self.custom_testcase.strip(): raise ValueError("Custom testcases are only allowed for self-tests (is_test=true)") return self