view 2.00/problem.py @ 20:5bfa23cd638d

More ZIP archive fixes One typo and one Windows incompatibility fixed.
author Oleg Oshmyan <chortos@inbox.lv>
date Mon, 14 Jun 2010 21:02:06 +0000
parents f2279b7602d3
children ec6f1a132109
line wrap: on
line source

#!/usr/bin/python
# Copyright (c) 2010 Chortos-2 <chortos@inbox.lv>

try:
	import config as _config, testcases as _testcases
except ImportError as e:
	import __main__
	__main__.import_error(e)

# LIBRARY and STDIO refer to interactive aka reactive problems
BATCH, OUTONLY, LIBRARY, STDIO, BESTOUT = xrange(5)

class Problem(object):
	__slots__ = 'name', 'config', 'cache', 'testcases'
	
	def __init__(prob, name):
		if not isinstance(name, basestring):
			# This shouldn't happen, of course
			raise TypeError, "Problem() argument 1 must be string, not " + str(type(name)).split('\'')[1]
		prob.name = name
		prob.config = _config.load_problem(name)
		prob.cache = type('Cache', (object,), {'padoutputtolength': 0})()
		prob.testcases = _testcases.load_problem(prob)
	
	def test(prob):
		real = max = 0
		for case in prob.testcases:
			r, m = case()
			real += r
			max += m
		return real, max