16
|
1 #!/usr/bin/python
|
|
2 # Copyright (c) 2010 Chortos-2 <chortos@inbox.lv>
|
|
3
|
|
4 try:
|
|
5 import config as _config, testcases as _testcases
|
|
6 except ImportError as e:
|
|
7 import __main__
|
|
8 __main__.import_error(e)
|
|
9
|
|
10 # LIBRARY and STDIO refer to interactive aka reactive problems
|
|
11 BATCH, OUTONLY, LIBRARY, STDIO, BESTOUT = xrange(5)
|
|
12
|
|
13 class Problem(object):
|
|
14 __slots__ = 'name', 'config', 'cache', 'testcases'
|
|
15
|
|
16 def __init__(prob, name):
|
|
17 if not isinstance(name, basestring):
|
|
18 # This shouldn't happen, of course
|
|
19 raise TypeError, "Problem() argument 1 must be string, not " + str(type(name)).split('\'')[1]
|
|
20 prob.name = name
|
|
21 prob.config = _config.load_problem(name)
|
|
22 prob.cache = type('Cache', (object,), {'padoutputtolength': 0})()
|
|
23 prob.testcases = _testcases.load_problem(prob)
|
|
24
|
|
25 def test(prob):
|
|
26 real = max = 0
|
|
27 for case in prob.testcases:
|
|
28 r, m = case()
|
|
29 real += r
|
|
30 max += m
|
|
31 return real, max |