Skip to content

Commit a378188

Browse files
committed
Improved judge
1 parent df8633b commit a378188

14 files changed

Lines changed: 53 additions & 85 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules/
22
server/solutions/
3-
judge0/result/
3+
judge/result/
44
solutions/

judge/compileProblem.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const compileProblem= async (lang , filename)=>{
1717
case "c++":
1818
case "cpp":
1919
file = path.basename(filename,'.cpp')+".out";
20-
console.log(file)
2120
cmd="cd "+"\""+ path.join(__dirname,"result/source") +"\""+ " && g++ -o \"" + path.join(__dirname,"result/binary/")+ "\""+file + " " +filename;
2221
break;
2322
case "java":
@@ -37,29 +36,32 @@ const compileProblem= async (lang , filename)=>{
3736

3837
//Run Compiled if okay the check result
3938

40-
async function runCompiled(lang,file,contest,problem,option){
39+
async function runCompiled(lang,file,contest,problem,option,t0){
4140

4241
var cmd;
4342
switch(lang){
4443
case "c":
45-
cmd= "cd \""+ path.join(__dirname,"result/binary") + "\" && ./" + file + " <\""+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt\"";
44+
cmd= "cd "+ "\""+ path.join(__dirname,"result/binary") + "\" && ./" + file + " <\""+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt\"";
4645
break;
4746
case "c++":
4847
case "cpp":
49-
cmd = "cd \""+ path.join(__dirname,"result/binary") + "\" && ./" + file +" <\""+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt\"";
48+
cmd = "cd "+"\""+ path.join(__dirname,"result/binary") + "\" && ./" + file +" <\""+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt\"";
5049
break;
5150
case "java":
52-
cmd = "cd \""+ path.join(__dirname,"result/binary") + "\" && java " + file +" <\""+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt\"";
51+
cmd = "cd "+"\""+ path.join(__dirname,"result/binary") + "\" && java " + file +" <\""+ path.join(__dirname,"result/input/")+contest+"/"+problem+".txt\"";
5352
}
5453

5554
return new Promise((resolve,reject)=>{
5655
exec(cmd,option,(error, stdout, stderr) => {
5756
if (error) {
58-
//console.log(error)
59-
reject(error);
57+
//console.log(error)
58+
let timelimit =0;
59+
const t1 = process.hrtime();
60+
timelimit = (t1[0]-t0[0]);
61+
console.log(timelimit);
62+
reject({error,timelimit});
6063
}
6164
var res=stdout;
62-
6365
resolve(res);
6466
});
6567
})
@@ -107,10 +109,11 @@ const base64tofile = async (base64,lang)=>{
107109
async function compileAndRunProblem(contest,problem,id,lang ,description,option){
108110
const filename= await base64tofile(description,lang);
109111
const file = await compileProblem(lang,filename);
110-
const result= await runCompiled(lang,file,contest,problem,option);
112+
const t0 = process.hrtime();
113+
const result= await runCompiled(lang,file,contest,problem,option,t0);
111114
const serverRes= await serverResult(contest,problem);
112115
const Result = await checkResult(result,serverRes);
113-
console.log(Result);
116+
//console.log(Result);
114117
return Result;
115118

116119
}

judge/result/binary/Solution.class

54 Bytes
Binary file not shown.

judge/result/binary/Solution.out

176 Bytes
Binary file not shown.

judge/result/source/Solution.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#include<stdio.h>
2-
int main()
3-
{
4-
int T,A,B,i;
5-
scanf("%d",&T);
6-
for(i=0;i<T;i++)
2+
int main()
73
{
8-
scanf("%d%d",&A,&B);
9-
printf("%d\n",A+B);
4+
printf("Welcome To CodeCamp");
105
}
11-
return 0;
12-
}
6+

judge/result/source/Solution.cpp

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,8 @@
1-
<<<<<<< HEAD
2-
<<<<<<< HEAD
3-
41
#include<bits/stdc++.h>
52
using namespace std;
6-
7-
int main(){
8-
unsigned long long sum=0;
9-
for(int i=0;i<10000;i++){
10-
for(int j=0;j<10;j++){
11-
sum+=1;
12-
}
13-
}
14-
cout<<sum<<"\n";
15-
return 0;
16-
}
17-
=======
18-
#include<stdio.h>
19-
203
int main()
214
{
22-
23-
printf("Welcome To CodeCamp");
24-
5+
//int arr[123456781];
6+
//cout << arr[12];
7+
while(1);
258
}
26-
>>>>>>> 919467b4979028359348c66d8bdf04c06bc03be5
27-
=======
28-
#include<bits/stdc++.h>
29-
#define mod 10001
30-
using namespace std;
31-
typedef long long LL;
32-
int main()
33-
{
34-
int n,a[10000],avg;
35-
LL b[mod],val=0,s=0,m;
36-
cin>>n;
37-
for(int i=0;i<n;i++)
38-
{
39-
cin>>a[i];
40-
s+=a[i];
41-
}
42-
avg=s/n;
43-
b[0]=0;
44-
for(int i = 0; i < n-1; i++){
45-
b[i+1] = b[i]+a[i]-avg;
46-
}
47-
sort(b,b+n);
48-
m = -b[n/2];
49-
for(int i=0;i<n;i++)
50-
{
51-
val += abs(b[i]+m);
52-
}
53-
cout<<val;
54-
return 0;
55-
}
56-
>>>>>>> v-0.1

judge/result/source/Solution.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import java.util.*;
2+
3+
public class Solution {
4+
5+
public static void main(String[] args) {
6+
7+
System.out.print("Welcome To CodeCamp");
8+
for(int i=0;i<1000000000;i++);
9+
}
10+
11+
}
12+

judge/routes/solution.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@ router.get('/:id',(req,res)=>{
3131
maxBuffer:pro.sourcelimit,
3232
encoding:'utf8'
3333
}
34-
judge.compileAndRunProblem(contest,problem,id,language ,description,option).then((result)=>{
35-
console.log(result);
34+
judge.compileAndRunProblem(contest,problem,id,language ,description,option).then((result)=>{
35+
console.log(result)
3636
res.send(result);
3737
}).catch((e)=>{
38+
console.log(e)
3839
var compileError = /(g[/++/]|gcc|javac)/;
39-
if(e.cmd.toString().match(compileError)){
40-
res.status(200).send('CE' + e);
41-
}else if(e.killed){
40+
if(e.toString().match(compileError)){
41+
res.status(200).send('CE');
42+
}else if(e.timelimit*1000>=option.timeout){
4243
res.status(200).send('TLE');
4344
}else{
4445
res.status(200).send('RE');

server/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ app.get('/',(req,res)=>{
5454
res.send()
5555
})
5656

57-
const port = process.env.PORT || 3000;
58-
app.listen(port);
57+
const port = process.env.PORT || 80;
58+
app.listen(port,'192.168.0.11');
5959
console.log('magic is started at ' + port)
6060

6161
module.exports={app}

server/models/user/user.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ UserSchema.statics.findByUsername=function(username,password,done){
133133
bcrypt.compare(password, user.password, function(err , res){
134134
if(err){
135135
return done(err);
136+
}else if(!res){
137+
return done(err);
136138
}else if(res){
137-
return done(null,user)
139+
return done(null,user);
138140
}
139141
})
140142
}

0 commit comments

Comments
 (0)