Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e8541d6

Browse filesBrowse files
committed
update validators
1 parent e415d47 commit e8541d6
Copy full SHA for e8541d6

File tree

Expand file treeCollapse file tree

3 files changed

+405
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+405
-1
lines changed

‎.gitignore

Copy file name to clipboardExpand all lines: .gitignore
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ header.tmp
33
a.out
44
/Implementations/build/
55
Implementations/kactl.pdf
6-
Contests/Tools/
76
.vscode
+237Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
#include <algorithm>
2+
#include <cstdio>
3+
#include <cstdlib>
4+
#include <cstring>
5+
#include <fstream>
6+
#include <iostream>
7+
#include <map>
8+
#include <set>
9+
#include <sstream>
10+
#include <unordered_set>
11+
#include <vector>
12+
13+
using namespace std;
14+
15+
#define GET_MACRO(_0, _1, _2, _3, NAME, ...) NAME
16+
17+
#define fail2(msg, line) \
18+
do { \
19+
const char *_msg = (msg); \
20+
if (_msg) { \
21+
cout << "fail[line " << line << "] " << _msg << endl; \
22+
} else { \
23+
cout << "fail[line " << line << "]" << endl; \
24+
} \
25+
exit(1); \
26+
} while (0)
27+
28+
#define fail1(msg) fail2((msg), __LINE__)
29+
30+
#define fail0() fail2(NULL, __LINE__)
31+
32+
#define fail(...) \
33+
GET_MACRO(_0, _1, ##__VA_ARGS__, fail2, fail1, fail0)(__VA_ARGS__)
34+
35+
#define fassert3(cond, msg, line) \
36+
do { \
37+
if (!(cond)) { \
38+
fail((msg), (line)); \
39+
} \
40+
} while (0)
41+
42+
#define fassert2(cond, msg) fassert3(cond, msg, __LINE__)
43+
44+
#define fassert1(cond) fassert3(cond, NULL, __LINE__)
45+
46+
#define fassert(...) \
47+
GET_MACRO(_0, ##__VA_ARGS__, fassert3, fassert2, fassert1)(__VA_ARGS__)
48+
49+
struct input {
50+
input(FILE *f) : uch(-2), fin(f), sin(NULL) {}
51+
input(istream &in) : uch(-2), fin(NULL), sin(&in) {}
52+
53+
int get() {
54+
if (uch != -2) {
55+
int ch = uch;
56+
uch = -2;
57+
return ch;
58+
} else if (fin) {
59+
return fgetc(fin);
60+
}
61+
return sin->get();
62+
}
63+
64+
void unget(int ch) { uch = ch; }
65+
66+
#define get_char() _get_char(__LINE__)
67+
68+
char _get_char(int _line_) {
69+
int ch = get();
70+
if (ch == -1) {
71+
fail("expected char", _line_);
72+
} else if (ch != '\n' && (ch < 32 || 126 < ch)) {
73+
fail("expected printable ascii", _line_);
74+
}
75+
return ch;
76+
}
77+
78+
#define get_eof() _get_eof(__LINE__)
79+
80+
void _get_eof(int _line_) { fassert(get() == -1, "expected eof", _line_); }
81+
82+
#define get_eol() _get_eol(__LINE__)
83+
84+
void _get_eol(int _line_) { fassert(get() == '\n', "expected eol", _line_); }
85+
86+
#define get_space() _get_space(__LINE__)
87+
88+
void _get_space(int _line_) {
89+
fassert(get() == ' ', "expected space", _line_);
90+
}
91+
92+
#define get_spaces() _get_spaces(__LINE__)
93+
94+
void _get_spaces(int _line_) {
95+
int ch;
96+
_get_space(_line_);
97+
for (ch = get(); ch == ' '; ch = get())
98+
;
99+
unget(ch);
100+
}
101+
102+
#define get_token() _get_token(__LINE__)
103+
104+
string _get_token(int _line_) {
105+
int ch;
106+
string res;
107+
for (ch = get(); ch != -1 && ch != '\n' && ch != ' '; ch = get()) {
108+
res += (char)ch;
109+
}
110+
fassert(!res.empty(), "expected token", _line_);
111+
unget(ch);
112+
return res;
113+
}
114+
115+
#define get_int(mn, mx) _get_int((mn), (mx), __LINE__)
116+
117+
long long _get_int(long long min, long long max, int _line_) {
118+
string tok = _get_token(_line_);
119+
long long res = atoll(tok.c_str());
120+
fassert(tok == to_string(res), "expected int", _line_);
121+
fassert(min <= res && res <= max, "int out of range", _line_);
122+
return res;
123+
}
124+
125+
#define get_line(mn, mx) _get_line((mn), (mx), __LINE__)
126+
127+
string _get_line(int min_length, int max_length, int _line_) {
128+
int ch;
129+
string res;
130+
for (ch = get(); ch != -1 && ch != '\n'; ch = get()) {
131+
res += (char)ch;
132+
fassert((int)res.size() <= max_length, "line too long", _line_);
133+
}
134+
fassert(min_length <= (int)res.size(), "line too short", _line_);
135+
unget(ch);
136+
return res;
137+
}
138+
139+
int uch;
140+
FILE *fin;
141+
istream *sin;
142+
};
143+
144+
vector<int> get_test_case_batches(int argc, char **argv) {
145+
vector<int> res;
146+
if (argc < 3) {
147+
return res;
148+
}
149+
150+
int test_id = atoi(argv[1]);
151+
if (test_id == 0) {
152+
return res;
153+
}
154+
155+
int batch = 0;
156+
ifstream fscorer_in(argv[2]);
157+
for (string ln; getline(fscorer_in, ln);) {
158+
if (ln.empty() || ln[0] == '#') {
159+
continue;
160+
}
161+
for (char &c : ln)
162+
if (c == ',')
163+
c = ' ';
164+
int sppos = ln.find(' ');
165+
if (sppos == string::npos) {
166+
continue;
167+
}
168+
istringstream sin(ln.substr(sppos + 1));
169+
170+
for (string part; sin >> part;) {
171+
int dash = part.find('-');
172+
if (dash == string::npos) {
173+
int num = atoi(part.c_str());
174+
if (num == test_id) {
175+
res.push_back(batch);
176+
break;
177+
}
178+
} else {
179+
int lo = atoi(part.substr(0, dash).c_str());
180+
int hi = atoi(part.substr(dash + 1).c_str());
181+
if (lo <= test_id && test_id <= hi) {
182+
res.push_back(batch);
183+
break;
184+
}
185+
}
186+
}
187+
batch++;
188+
}
189+
return res;
190+
}
191+
192+
#define gi(a, b) in.get_int(a, b)
193+
#define gl(a, b) in.get_line(a, b)
194+
#define gs() in.get_space()
195+
#define ge() in.get_eol()
196+
#define gt() in.get_token()
197+
198+
int main(int argc, char **argv) {
199+
int tc = atoi(argv[1]); // test id
200+
cerr << "TEST #: " << tc << endl;
201+
202+
input in(cin);
203+
204+
int N = in.get_int(1, 100000);
205+
in.get_eol();
206+
207+
for (int i = 0; i < N; i++) {
208+
if (i)
209+
in.get_space();
210+
int c = in.get_int(0, N - 1);
211+
}
212+
in.get_eol();
213+
in.get_eof();
214+
215+
#ifndef LOCAL // check batching
216+
const int NUM_BATCHES = 5; // modify
217+
vector<int> batches = get_test_case_batches(argc, argv);
218+
cerr << "BATCHES: {";
219+
for (int i = 0; i < (int)batches.size(); ++i) {
220+
if (i)
221+
cerr << ", ";
222+
fassert(0 <= batches[i] && batches[i] < NUM_BATCHES, "invalid batching");
223+
cerr << batches[i];
224+
}
225+
cerr << "}\n";
226+
for (int batch = 0; batch < NUM_BATCHES; ++batch) {
227+
bool contains_batch =
228+
find(begin(batches), end(batches), batch) != end(batches);
229+
bool calc_batch = 1;
230+
// modify calc_batch below to actually check whether test is in batch
231+
232+
fassert(calc_batch == contains_batch, "wrong batching");
233+
}
234+
#endif
235+
236+
cerr << "VALIDATED!" << endl;
237+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.