Skip to main content

aj_models/
problems.rs

1//! Structs for problems
2
3use serde::{Deserialize, Serialize};
4
5/// Problem's config
6#[derive(Deserialize, Serialize, Clone, Debug)]
7pub struct ProblemConfig {
8    /// Problem's owner's user id (optional)
9    pub owner_id: Option<i64>,
10    /// Problem's type
11    pub r#type: ProblemType,
12    /// Merge subgroups
13    pub merge_subgroups: bool,
14    /// Problems's contest id
15    pub contest_id: i64,
16    /// Problem's index in contest
17    pub problem_index: i64,
18    /// Problem's name (ru)
19    pub name_ru: String,
20    /// Problem's name (en)
21    pub name_en: String,
22    /// Testing time limit in milliseconds
23    pub time_limit_ms: i32,
24    /// Testing memory limit in megabytes
25    pub memory_limit_mb: i32,
26    /// Path to the checker relative to problem's path
27    pub checker_path: String,
28    /// Path to the directory, which contains directories with tests inputs and outputs, relative to problem's path
29    pub tests_path: String,
30    /// Testing subgroups
31    pub subgroups: Vec<Subgroup>,
32}
33
34/// Problem config visible for all users
35#[derive(Deserialize, Serialize, Clone, Debug)]
36#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
37pub struct PublicProblemConfig {
38    /// Problem's id
39    pub id: i64,
40    /// Problem's owner id (optional)
41    pub owner_id: Option<i64>,
42    /// Problem's type
43    pub r#type: ProblemType,
44    /// Merge subgroups
45    pub merge_subgroups: bool,
46    /// Problems's contest id
47    pub contest_id: i64,
48    /// Problem's index in contest
49    pub problem_index: i64,
50    /// Problem's name (ru)
51    pub name_ru: String,
52    /// Problem's name (en)
53    pub name_en: String,
54    /// Testing time limit in milliseconds
55    pub time_limit_ms: i32,
56    /// Testing memory limit in megabytes
57    pub memory_limit_mb: i32,
58    /// Problem's subgroups
59    pub subgroups: Vec<Subgroup>,
60}
61
62/// Problem's type
63#[derive(Deserialize, Serialize, Debug, Clone)]
64#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
65#[cfg_attr(
66    feature = "sqlx",
67    sqlx(type_name = "problem_type", rename_all = "snake_case")
68)]
69#[serde(rename_all = "snake_case")]
70pub enum ProblemType {
71    /// Default problem
72    Default,
73    /// Interactive problem
74    Interactive,
75    /// Run-twice problem
76    RunTwice,
77    /// Run-twice problem, where both runs are interactive
78    RunTwiceInteractive,
79    /// Run-twice problem, where the first run is interactive, and the second run is a default one
80    RunTwiceFirstInteractive,
81    /// Run-twice problem, where the first run is a default one, and the second run is interactive
82    RunTwiceSecondInteractive,
83}
84
85/// Testing subgroup
86#[derive(Deserialize, Serialize, Debug, Clone)]
87#[cfg_attr(feature = "sqlx", derive(sqlx::FromRow))]
88pub struct Subgroup {
89    /// Subgroup's type
90    pub r#type: SubgroupType,
91    /// Array of tests' indexes of the subgroup
92    pub tests: Vec<i32>,
93    /// Maximum score which can be obtained from the subgroup
94    pub score: Option<i32>,
95    /// Maximum score which can be obtained from the each of subgroup's tests
96    pub score_per_test: Option<i32>,
97    /// Indexes of the subgroups, all of them must have `Ok` verdict to test on this subgroup.
98    /// Also, they must be less than index of this subgroup
99    pub depends_on: Vec<usize>,
100}
101
102/// Subgroup's type
103#[derive(Deserialize, Serialize, Debug, Clone, PartialEq)]
104#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
105#[cfg_attr(
106    feature = "sqlx",
107    sqlx(type_name = "subgroup_type", rename_all = "snake_case")
108)]
109#[serde(rename_all = "snake_case")]
110pub enum SubgroupType {
111    /// Don't count score for this subgroup
112    Sample,
113    /// Count score for this subgroup
114    Main,
115}