Skip to content

Commit c7ec558

Browse files
authored
Update problem 61 & 87 (#93)
* update problem 61 * update problem 87
1 parent 511477b commit c7ec558

File tree

23 files changed

+1372675
-495
lines changed

23 files changed

+1372675
-495
lines changed

algorithmic/problems/61/check.cpp

Lines changed: 93 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,109 @@
11
#include "testlib.h"
2-
#include <sstream>
3-
2+
#include <vector>
3+
#include <algorithm>
44
using namespace std;
55

6-
int main(int argc, char * argv[])
7-
{
8-
setName("compare ordered sequences of signed int%d numbers", 8 * int(sizeof(long long)));
9-
6+
int main(int argc, char * argv[]) {
107
registerTestlibCmd(argc, argv);
11-
12-
int n = 0;
13-
string firstElems;
14-
15-
double total_ratio = 0;
16-
double total_unbounded_ratio = 0;
17-
18-
while (!ans.seekEof() && !ouf.seekEof())
19-
{
20-
n++;
21-
long long j = ans.readLong();
22-
long long p = ouf.readLong();
23-
if (p < j)
24-
quitf(_wa, "%d%s numbers differ - expected: '%s', found: '%s'", n, englishEnding(n).c_str(), vtos(j).c_str(), vtos(p).c_str());
25-
double ratio = min(1.0, p / j * 0.8);
26-
double unbounded_ratio = p / j * 0.8;
8+
9+
int T = inf.readInt();
10+
int total_cases = 0;
11+
double total_ratio = 0;
12+
double total_unbounded_ratio = 0;
13+
14+
for (int tc = 1; tc <= T; tc++) {
15+
int n = inf.readInt();
16+
int m = inf.readInt();
17+
long long c = inf.readLong();
18+
19+
vector<long long> a(n + 1, 0);
20+
for (int i = 1; i <= n; i++) {
21+
long long ai = inf.readLong();
22+
a[i] = a[i-1] + ai;
23+
}
24+
25+
vector<long long> b(m + 1, 0);
26+
for (int i = 1; i <= m; i++) {
27+
long long bi = inf.readLong();
28+
b[i] = b[i-1] + bi;
29+
}
30+
31+
// Read reference answer
32+
long long ref_score = ans.readLong();
33+
34+
// Read participant's answer
35+
int d = ouf.readInt(1, n, format("d for test case %d", tc));
36+
37+
vector<pair<int,int>> segments;
38+
for (int i = 0; i < d; i++) {
39+
int l = ouf.readInt(1, n, format("l for segment %d in test case %d", i+1, tc));
40+
int r = ouf.readInt(l, n, format("r for segment %d in test case %d", i+1, tc));
41+
segments.push_back({l, r});
42+
}
43+
44+
// Validate segments
45+
vector<bool> covered(n + 1, false);
46+
for (auto [l, r] : segments) {
47+
for (int day = l; day <= r; day++) {
48+
if (covered[day]) {
49+
quitf(_wa, "Day %d is covered multiple times in test case %d", day, tc);
50+
}
51+
covered[day] = true;
52+
}
53+
}
54+
55+
for (int day = 1; day <= n; day++) {
56+
if (!covered[day]) {
57+
quitf(_wa, "Day %d is not covered in test case %d", day, tc);
58+
}
59+
}
60+
61+
// Check chronological order
62+
for (int i = 0; i + 1 < d; i++) {
63+
if (segments[i].second >= segments[i+1].first) {
64+
quitf(_wa, "Segments are not in chronological order in test case %d", tc);
65+
}
66+
}
67+
68+
// Calculate participant's score
69+
long long total_ranks = 0;
70+
for (auto [l, r] : segments) {
71+
long long exp = a[r] - a[l-1];
72+
int rank = 0;
73+
for (int k = 1; k <= m; k++) {
74+
if (exp >= b[k]) rank = k;
75+
else break;
76+
}
77+
total_ranks += rank;
78+
}
79+
80+
long long participant_score = total_ranks - c * d;
81+
82+
if (participant_score < ref_score) {
83+
quitf(_wa, "Test case %d: score %lld is less than reference %lld",
84+
tc, participant_score, ref_score);
85+
}
86+
87+
double ratio = min(1.0, (double)participant_score / ref_score * 0.8);
88+
double unbounded_ratio = (double)participant_score / ref_score * 0.8;
2789

2890
total_ratio += ratio;
2991
total_unbounded_ratio += unbounded_ratio;
92+
total_cases++;
3093
}
3194

32-
total_ratio /= n;
33-
total_unbounded_ratio /= n;
95+
total_ratio /= total_cases;
96+
total_unbounded_ratio /= total_cases;
3497
double score = total_ratio * 100;
3598
double unbounded_score = total_unbounded_ratio * 100;
36-
37-
int extraInAnsCount = 0;
38-
39-
while (!ans.seekEof())
40-
{
41-
ans.readLong();
42-
extraInAnsCount++;
43-
}
4499

45-
int extraInOufCount = 0;
46-
47-
while (!ouf.seekEof())
48-
{
49-
ouf.readLong();
50-
extraInOufCount++;
100+
if (!ouf.seekEof()) {
101+
quitf(_wa, "Extra output found");
51102
}
52-
53-
if (extraInAnsCount > 0)
54-
quitf(_wa, "Answer contains longer sequence [length = %d], but output contains %d elements", n + extraInAnsCount, n);
55-
56-
if (extraInOufCount > 0)
57-
quitf(_wa, "Output contains longer sequence [length = %d], but answer contains %d elements", n + extraInOufCount, n);
58103

59104
string msg = format(
60-
"Correct! Ratio: %.6f (Score: %.2f). RatioUnbounded: %.6f (ScoreUnbounded: %.2f)",
61-
total_ratio, score, total_unbounded_ratio, unbounded_score);
62-
105+
"Correct! Ratio: %.6f (Score: %.2f). RatioUnbounded: %.6f (ScoreUnbounded: %.2f)",
106+
total_ratio, score, total_unbounded_ratio, unbounded_score);
107+
63108
quitp(total_ratio, msg.c_str());
64-
}
109+
}

algorithmic/problems/61/config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ checker: check.cpp
77
cheker_type: testlib
88
subtasks:
99
- score: 100
10-
n_cases: 3
10+
n_cases: 10

0 commit comments

Comments
 (0)