@@ -10,6 +10,7 @@ class CodeExecutor
1010{
1111 public function executeUserCode (string $ code , Problem $ problem , mixed $ userId ): array
1212 {
13+ $ maxRuntime = min ($ problem ->getMaxRuntime (), 1 );
1314 $ results = [];
1415 $ submissionsRoot = getcwd () . '/submissions ' ;
1516 $ userProblemDir = "$ submissionsRoot/ $ userId/ {$ problem ->getId ()}" ;
@@ -18,7 +19,6 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
1819 mkdir ($ userProblemDir , 0777 , true );
1920 }
2021
21- // Сохраняем решение
2222 file_put_contents ("$ userProblemDir/solution.py " , $ code );
2323
2424 foreach ($ problem ->getTestCases () as $ i => $ input ) {
@@ -32,11 +32,11 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
3232 'docker ' , 'create ' ,
3333 '--network ' , 'none ' ,
3434 '--cpus ' , '0.5 ' ,
35- '--memory ' , '256m ' ,
35+ '--memory ' , '64m ' ,
3636 '--name ' , $ containerName ,
3737 'python:3.10-slim ' ,
3838 'bash ' , '-c ' ,
39- "timeout 2s python submissions/ $ userId/ {$ problem ->getId ()}/solution.py < submissions/ $ userId/ {$ problem ->getId ()}/input.txt "
39+ "timeout { $ maxRuntime } s python submissions/$ userId/ {$ problem ->getId ()}/solution.py < submissions/ $ userId/ {$ problem ->getId ()}/input.txt "
4040 ]);
4141 $ create ->mustRun ();
4242
@@ -50,7 +50,7 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
5050 $ start = new Process ([
5151 'docker ' , 'start ' , '-a ' , $ containerName
5252 ]);
53- $ start ->setTimeout (4 );
53+ $ start ->setTimeout ($ maxRuntime + 2 );
5454 $ start ->run ();
5555
5656 $ stdout = trim ($ start ->getOutput ());
@@ -85,7 +85,7 @@ public function executeUserCode(string $code, Problem $problem, mixed $userId):
8585 $ results [] = [
8686 'input ' => $ input ,
8787 'expected ' => $ problem ->getExpectedOutputs ()[$ i ],
88- 'output ' => null ,
88+ 'output ' => " Time limit exceeded " ,
8989 'passed ' => false ,
9090 'error ' => 'Time limit exceeded ' ,
9191 ];
0 commit comments