-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathcheck.cpp
More file actions
109 lines (89 loc) · 3.44 KB
/
check.cpp
File metadata and controls
109 lines (89 loc) · 3.44 KB
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
#include "testlib.h"
#include <vector>
#include <algorithm>
using namespace std;
int main(int argc, char * argv[]) {
registerTestlibCmd(argc, argv);
int T = inf.readInt();
int total_cases = 0;
double total_ratio = 0;
double total_unbounded_ratio = 0;
for (int tc = 1; tc <= T; tc++) {
int n = inf.readInt();
int m = inf.readInt();
long long c = inf.readLong();
vector<long long> a(n + 1, 0);
for (int i = 1; i <= n; i++) {
long long ai = inf.readLong();
a[i] = a[i-1] + ai;
}
vector<long long> b(m + 1, 0);
for (int i = 1; i <= m; i++) {
long long bi = inf.readLong();
b[i] = b[i-1] + bi;
}
// Read reference answer
long long ref_score = ans.readLong();
// Read participant's answer
int d = ouf.readInt(1, n, format("d for test case %d", tc));
vector<pair<int,int>> segments;
for (int i = 0; i < d; i++) {
int l = ouf.readInt(1, n, format("l for segment %d in test case %d", i+1, tc));
int r = ouf.readInt(l, n, format("r for segment %d in test case %d", i+1, tc));
segments.push_back({l, r});
}
// Validate segments
vector<bool> covered(n + 1, false);
for (auto [l, r] : segments) {
for (int day = l; day <= r; day++) {
if (covered[day]) {
quitf(_wa, "Day %d is covered multiple times in test case %d", day, tc);
}
covered[day] = true;
}
}
for (int day = 1; day <= n; day++) {
if (!covered[day]) {
quitf(_wa, "Day %d is not covered in test case %d", day, tc);
}
}
// Check chronological order
for (int i = 0; i + 1 < d; i++) {
if (segments[i].second >= segments[i+1].first) {
quitf(_wa, "Segments are not in chronological order in test case %d", tc);
}
}
// Calculate participant's score
long long total_ranks = 0;
for (auto [l, r] : segments) {
long long exp = a[r] - a[l-1];
int rank = 0;
for (int k = 1; k <= m; k++) {
if (exp >= b[k]) rank = k;
else break;
}
total_ranks += rank;
}
long long participant_score = total_ranks - c * d;
if (participant_score < ref_score) {
quitf(_wa, "Test case %d: score %lld is less than reference %lld",
tc, participant_score, ref_score);
}
double ratio = min(1.0, (double)participant_score / ref_score * 0.8);
double unbounded_ratio = (double)participant_score / ref_score * 0.8;
total_ratio += ratio;
total_unbounded_ratio += unbounded_ratio;
total_cases++;
}
total_ratio /= total_cases;
total_unbounded_ratio /= total_cases;
double score = total_ratio * 100;
double unbounded_score = total_unbounded_ratio * 100;
if (!ouf.seekEof()) {
quitf(_wa, "Extra output found");
}
string msg = format(
"Correct! Ratio: %.6f (Score: %.2f). RatioUnbounded: %.6f (ScoreUnbounded: %.2f)",
total_ratio, score, total_unbounded_ratio, unbounded_score);
quitp(total_ratio, msg.c_str());
}