judger.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. #include "uoj_judger.h"
  2. struct SubtaskInfo {
  3. bool passed;
  4. int score;
  5. SubtaskInfo() {
  6. }
  7. SubtaskInfo(const bool &_p, const int &_s)
  8. : passed(_p), score(_s){}
  9. };
  10. void ordinary_test() {
  11. int n = conf_int("n_tests", 10);
  12. int m = conf_int("n_ex_tests", 0);
  13. int nT = conf_int("n_subtasks", 0);
  14. if (conf_is ("allow_proc", "on"))
  15. setenv ("UOJ_ALLOW_PROC", "1", 1);
  16. if (!conf_is("submit_answer", "on")) {
  17. report_judge_status_f("Compiling");
  18. RunCompilerResult c_ret = !conf_is("with_implementer", "on") ? compile("answer") : compile_with_implementer("answer");
  19. if (!c_ret.succeeded) {
  20. end_judge_compile_error(c_ret);
  21. }
  22. }
  23. bool passed = true;
  24. if (nT == 0) {
  25. for (int i = 1; i <= n; i++) {
  26. report_judge_status_f("Judging Test #%d", i);
  27. PointInfo po = test_point("answer", i);
  28. if (po.scr != 100) {
  29. passed = false;
  30. }
  31. po.scr = scale_score(po.scr, conf_int("point_score", i, 100 / n));
  32. add_point_info(po);
  33. }
  34. } else if (nT == 1) {
  35. for (int i = 1; i <= n; i++) {
  36. report_judge_status_f("Judging Test #%d", i);
  37. PointInfo po = test_point("answer", i);
  38. if (po.scr != 100) {
  39. passed = false;
  40. po.scr = i == 1 ? 0 : -100;
  41. add_point_info(po);
  42. break;
  43. } else {
  44. po.scr = i == 1 ? 100 : 0;
  45. add_point_info(po);
  46. }
  47. }
  48. } else {
  49. map<int, SubtaskInfo> subtasks;
  50. map<int,int> minScore;
  51. for (int t = 1; t <= nT; t++) {
  52. string subtaskType = conf_str("subtask_type", t, "packed");
  53. int startI = conf_int("subtask_end", t - 1, 0) + 1;
  54. int endI = conf_int("subtask_end", t, 0);
  55. vector<PointInfo> points;
  56. minScore[t] = 100;
  57. vector<int> dependences;
  58. if (conf_str("subtask_dependence", t, "none") == "many") {
  59. string cur = "subtask_dependence_" + vtos(t);
  60. int p = 1;
  61. while (conf_int(cur, p, 0) != 0) {
  62. dependences.push_back(conf_int(cur, p, 0));
  63. p++;
  64. }
  65. } else if (conf_int("subtask_dependence", t, 0) != 0) {
  66. dependences.push_back(conf_int("subtask_dependence", t, 0));
  67. }
  68. bool skipped = false;
  69. for (vector<int>::iterator it = dependences.begin(); it != dependences.end(); it++) {
  70. if (subtaskType == "packed") {
  71. if (!subtasks[*it].passed) {
  72. skipped = true;
  73. break;
  74. }
  75. } else if (subtaskType == "min") {
  76. minScore[t] = min(minScore[t], minScore[*it]);
  77. }
  78. }
  79. if (skipped) {
  80. add_subtask_info(t, 0, "Skipped", points);
  81. continue;
  82. }
  83. int tfull = conf_int("subtask_score", t, 100 / nT);
  84. int tscore = scale_score(minScore[t], tfull);
  85. string info = "Accepted";
  86. for (int i = startI; i <= endI; i++) {
  87. report_judge_status_f("Judging Test #%d of Subtask #%d", i, t);
  88. PointInfo po = test_point("answer", i);
  89. if (subtaskType == "packed") {
  90. if (po.scr != 100) {
  91. passed = false;
  92. po.scr = i == startI ? 0 : -tfull;
  93. tscore = 0;
  94. points.push_back(po);
  95. info = po.info;
  96. break;
  97. } else {
  98. po.scr = i == startI ? tfull : 0;
  99. tscore = tfull;
  100. points.push_back(po);
  101. }
  102. } else if (subtaskType == "min") {
  103. minScore[t] = min(minScore[t], po.scr);
  104. if (po.scr != 100) {
  105. passed = false;
  106. }
  107. po.scr = scale_score(po.scr, tfull);
  108. if (po.scr <= tscore) {
  109. tscore = po.scr;
  110. points.push_back(po);
  111. info = po.info;
  112. } else {
  113. points.push_back(po);
  114. }
  115. }
  116. }
  117. subtasks[t] = SubtaskInfo(info == "Accepted", tscore);
  118. add_subtask_info(t, tscore, info, points);
  119. }
  120. }
  121. if (conf_is("submit_answer", "on") || !passed) {
  122. end_judge_ok();
  123. }
  124. tot_score = 100;
  125. for (int i = 1; i <= m; i++) {
  126. report_judge_status_f("Judging Extra Test #%d", i);
  127. PointInfo po = test_point("answer", -i);
  128. if (po.scr != 100) {
  129. po.num = -1;
  130. po.info = "Extra Test Failed : " + po.info + " on " + vtos(i);
  131. po.scr = -3;
  132. add_point_info(po);
  133. end_judge_ok();
  134. }
  135. }
  136. if (m != 0) {
  137. PointInfo po(-1, 0, -1, -1, "Extra Test Passed", "", "", "");
  138. add_point_info(po);
  139. }
  140. end_judge_ok();
  141. }
  142. void hack_test() {
  143. if (conf_is("submit_answer", "on")) {
  144. end_judge_judgement_failed("Hack is not supported in this problem.");
  145. } else {
  146. RunCompilerResult c_ret = !conf_is("with_implementer", "on") ? compile("answer") : compile_with_implementer("answer");
  147. if (!c_ret.succeeded) {
  148. end_judge_compile_error(c_ret);
  149. }
  150. TestPointConfig tpc;
  151. tpc.input_file_name = work_path + "/hack_input.txt";
  152. tpc.output_file_name = work_path + "/pro_output.txt";
  153. tpc.answer_file_name = work_path + "/std_output.txt";
  154. PointInfo po = test_hack_point("answer", tpc);
  155. add_point_info(po);
  156. end_judge_ok();
  157. }
  158. }
  159. void sample_test() {
  160. if (conf_is("submit_answer", "on")) {
  161. int n = conf_int("n_tests", 10);
  162. for (int i = 1; i <= n; i++) {
  163. report_judge_status_f("Judging Test #%d", i);
  164. if (conf_is("check_existence_only_in_sample_test", "on")) {
  165. TestPointConfig tpc = TestPointConfig();
  166. tpc.auto_complete(i);
  167. string usrout = file_preview(tpc.output_file_name);
  168. if (usrout == "") {
  169. add_point_info(PointInfo(i, 0, -1, -1,
  170. "default",
  171. file_preview(tpc.input_file_name), usrout,
  172. "wrong answer empty file\n"));
  173. } else {
  174. PointInfo po = PointInfo(i, 100, -1, -1,
  175. "default",
  176. file_preview(tpc.input_file_name), usrout,
  177. "ok nonempty file\n");
  178. po.scr = scale_score(po.scr, conf_int("point_score", i, 100 / n));
  179. add_point_info(po);
  180. }
  181. } else {
  182. PointInfo po = test_point("answer", i);
  183. if (po.scr != 0) {
  184. po.info = "Accepted";
  185. po.scr = 100;
  186. }
  187. po.scr = scale_score(po.scr, conf_int("point_score", i, 100 / n));
  188. po.res = "no comment";
  189. add_point_info(po);
  190. }
  191. }
  192. end_judge_ok();
  193. } else {
  194. report_judge_status_f("Compiling");
  195. RunCompilerResult c_ret = !conf_is("with_implementer", "on") ? compile("answer") : compile_with_implementer("answer");
  196. if (!c_ret.succeeded) {
  197. end_judge_compile_error(c_ret);
  198. }
  199. int n = conf_int("n_sample_tests", 0);
  200. bool passed = true;
  201. for (int i = 1; i <= n; i++) {
  202. report_judge_status_f("Judging Sample Test #%d", i);
  203. PointInfo po = test_point("answer", -i);
  204. po.num = i;
  205. if (po.scr != 100) {
  206. passed = false;
  207. }
  208. po.scr = scale_score(po.scr, 100 / n);
  209. add_point_info(po);
  210. }
  211. if (passed) {
  212. tot_score = 100;
  213. }
  214. end_judge_ok();
  215. }
  216. }
  217. void custom_test() {
  218. if (conf_is("submit_answer", "on")) {
  219. end_judge_judgement_failed("Custom test is not supported in this problem.");
  220. } else {
  221. report_judge_status_f("Compiling");
  222. RunCompilerResult c_ret = !conf_is("with_implementer", "on") ? compile("answer") : compile_with_implementer("answer");
  223. if (!c_ret.succeeded) {
  224. end_judge_compile_error(c_ret);
  225. }
  226. report_judge_status_f("Judging");
  227. add_custom_test_info(ordinary_custom_test("answer"));
  228. end_judge_ok();
  229. }
  230. }
  231. int main(int argc, char **argv) {
  232. judger_init(argc, argv);
  233. if (conf_is("test_new_hack_only", "on")) {
  234. hack_test();
  235. } else if (conf_is("test_sample_only", "on")) {
  236. sample_test();
  237. } else if (conf_is("custom_test", "on")) {
  238. custom_test();
  239. } else {
  240. ordinary_test();
  241. }
  242. }