forked from lixin-wei/acm-resolver
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hiho-resolver.js
152 lines (149 loc) · 5.33 KB
/
hiho-resolver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
function Resolver(solutions, users, problem_count, frozen_seconds){
this.solutions = solutions;
this.users = users;
this.problem_count = problem_count;
this.frozen_seconds = frozen_seconds;
this.operations = [];
}
Resolver.prototype.status = function(problem) {
if(problem.old_verdict == 'NA' && problem.new_verdict == 'NA')
return "untouched";
else if(problem.old_verdict == 'AC')
return "ac";
else if(problem.new_verdict == 'NA')
return "failed";
else
return "frozen";
}
Resolver.prototype.calcOperations = function() {
this.rank = {};
for(var solution_id in this.solutions) {
var sol = this.solutions[solution_id];
if(['WT', 'CE', 'VE', 'SE'].indexOf(sol.verdict) != -1) {
continue;
}
if(Object.keys(this.rank).indexOf(sol.user_id) == -1) {
this.rank[sol.user_id] = {'score':0, 'penalty':0, 'user_id':sol.user_id};
this.rank[sol.user_id].problem = {};
for(var i = 1; i <= this.problem_count; i++) {
this.rank[sol.user_id].problem[i] = {
'problem_index': i - 1,
'old_penalty':0,
'new_penalty':0,
'old_verdict':'NA',
'new_verdict':'NA',
'old_submissions':0, //include the AC submission
'frozen_submissions': 0,
'new_submissions':0,
'ac_penalty':0
};
}
}
if(this.rank[sol.user_id].problem[sol.problem_index].old_verdict=='AC') {
continue;
}
if(sol.submitted_seconds <= this.frozen_seconds) {
this.rank[sol.user_id].problem[sol.problem_index].old_verdict = sol.verdict;
if(sol.verdict == 'AC') {
this.rank[sol.user_id].problem[sol.problem_index].old_submissions++;
this.rank[sol.user_id].problem[sol.problem_index].ac_penalty = sol.submitted_seconds;
this.rank[sol.user_id].problem[sol.problem_index].old_penalty = this.rank[sol.user_id].problem[sol.problem_index].ac_penalty + 20 * 60 * (this.rank[sol.user_id].problem[sol.problem_index].old_submissions - 1);
this.rank[sol.user_id].score++;
this.rank[sol.user_id].penalty += this.rank[sol.user_id].problem[sol.problem_index].old_penalty;
}
else {
this.rank[sol.user_id].problem[sol.problem_index].old_submissions++;
}
}
else { //after standings get frozen
if(this.rank[sol.user_id].problem[sol.problem_index].new_verdict=='AC') {
this.rank[sol.user_id].problem[sol.problem_index].frozen_submissions++;
continue;
}
this.rank[sol.user_id].problem[sol.problem_index].new_verdict = sol.verdict;
if(sol.verdict == 'AC') {
this.rank[sol.user_id].problem[sol.problem_index].frozen_submissions++;
this.rank[sol.user_id].problem[sol.problem_index].new_submissions = this.rank[sol.user_id].problem[sol.problem_index].old_submissions + this.rank[sol.user_id].problem[sol.problem_index].frozen_submissions;
this.rank[sol.user_id].problem[sol.problem_index].ac_penalty = sol.submitted_seconds;
this.rank[sol.user_id].problem[sol.problem_index].new_penalty = this.rank[sol.user_id].problem[sol.problem_index].ac_penalty + 20 * 60 * (this.rank[sol.user_id].problem[sol.problem_index].new_submissions - 1);
}
else {
this.rank[sol.user_id].problem[sol.problem_index].frozen_submissions++;
}
}
}
var uids = Object.keys(this.rank);
this.rank2 = [];
for(var key in uids) {
var user_id = uids[key];
this.rank2.push(this.rank[user_id]);
}
this.rank2.sort(function(a, b){
if(a.score == b.score) {
return a.penalty - b.penalty;
}
return b.score - a.score;
});
var rnk = 0;
for (var i = 0; i < this.rank2.length; ++i) {
var user_id = this.rank2[i].user_id;
if (this.users[user_id].is_exclude === true) {
this.rank2[i].rank_show = "*";
this.rank[user_id].rank_show = "*";
} else {
rnk++;
this.rank2[i].rank_show = rnk;
this.rank[user_id].rank_show = rnk;
}
}
//this.rank2.length = 200;
this.rank_frozen = $.extend(true, [], this.rank2);
for(var i = this.rank2.length - 1; i >= 0; i--) {
var flag = true;
while(flag) {
flag = false;
for(var j = 1; j <= this.problem_count; j++) {
if(this.status(this.rank2[i].problem[j]) == "frozen") {
flag = true;
var op = {
id: this.operations.length,
user_id: this.rank2[i].user_id,
problem_index: j,
old_verdict: this.rank2[i].problem[j].old_verdict,
new_verdict: this.rank2[i].problem[j].new_verdict,
old_submissions: this.rank2[i].problem[j].old_submissions,
frozen_submissions: this.rank2[i].problem[j].frozen_submissions,
new_submissions: this.rank2[i].problem[j].new_submissions,
old_rank: i,
new_rank: -1,
old_rank_show: this.rank2[i].rank_show,
new_rank_show: -1,
old_penalty: this.rank2[i].problem[j].old_penalty,
new_penalty: this.rank2[i].problem[j].new_penalty
};
var tmp = this.rank2[i];
if(tmp.problem[j].new_verdict == 'AC') {
tmp.score++;
tmp.penalty += tmp.problem[j].new_penalty;
}
tmp.problem[j].old_verdict = tmp.problem[j].new_verdict;
tmp.problem[j].new_verdict = "NA";
var k = i -1;
while(k >= 0 && (this.rank2[k].score < tmp.score || this.rank2[k].score == tmp.score && this.rank2[k].penalty > tmp.penalty)) {
if (tmp.rank_show !== "*" && this.rank2[k].rank_show !== "*") {
tmp.rank_show--;
this.rank2[k].rank_show++;
}
this.rank2[k+1] = this.rank2[k];
k--;
}
this.rank2[k+1] = tmp;
op.new_rank = k+1;
op.new_rank_show = tmp.rank_show;
this.operations.push(op);
break;
}
}
}
}
}