public JudgeContext(JudgeTask task, JudgeResult result, string tempDirectory, ILangConfig langConfig) { Task = task; TempDirectory = tempDirectory; LangConfig = langConfig; Result = result; }
/// <summary> /// 获取时间补偿系数 /// </summary> private static double GetTimeCompensation(ILangConfig langConfig) { if (langConfig is ProgramLangConfig config) { return(config.TimeCompensation); } return(1); }
/// <summary> /// 创建JudgeTask实例 /// </summary> /// <param name="submitId">提交ID</param> /// <param name="problemId">问题ID</param> /// <param name="dataVersion">测试数据版本</param> /// <param name="language">语言</param> /// <param name="sourceCode">源代码</param> /// <param name="author">作者</param> /// <param name="timeLimit">时间限制</param> /// <param name="memoryLimit">内存限制</param> /// <param name="judgeAllCases">是否评测全部样例(即使遇到错误答案)</param> /// <param name="judgeType">评测类型</param> /// <returns>JudgeTask实例</returns> public static JudgeContext Create(int submitId, int problemId, string dataVersion, string language, string sourceCode, string author = "", int timeLimit = 1000, int memoryLimit = 262144, bool judgeAllCases = false, JudgeType judgeType = JudgeType.ProgramJudge) { ILangConfig langConfig = ConfigManager.GetLanguageConfig(language); if (langConfig == null) { throw new JudgeException("Unsupported language: " + language); } // 分配评测临时目录 string tempDirectory = RandomString.Next(16); if (langConfig is ProgramLangConfig) { ProgramLangConfig langCfg = langConfig as ProgramLangConfig; tempDirectory = GetTempDirectory(langCfg.JudgeDirectory); UpdatePathInfo(langCfg, tempDirectory); } double timeCompensation = GetTimeCompensation(langConfig); JudgeTask task = new JudgeTask { SubmitId = submitId, ProblemId = problemId, DataVersion = dataVersion, Language = language, SourceCode = sourceCode, Author = author, TimeLimit = (int)(timeLimit / timeCompensation), MemoryLimit = memoryLimit, JudgeAllCases = judgeAllCases, JudgeType = judgeType }; JudgeResult result = new JudgeResult { SubmitId = task.SubmitId, ProblemId = task.ProblemId, Author = task.Author, JudgeDetail = "", MemoryCost = Config.MinimumMemoryCost, TimeCost = 0, PassRate = 0, ResultCode = JudgeResultCode.Accepted }; return(new JudgeContext(task, result, tempDirectory, langConfig)); }
/// <summary> /// 获取时间补偿系数 /// </summary> /// <param name="langConfig">语言配置</param> /// <returns>时间补偿系数</returns> private static double GetTimeCompensation(ILangConfig langConfig) { return(langConfig is ProgramLangConfig ? (langConfig as ProgramLangConfig).TimeCompensation : 1); }