diff 2.00/problem.py @ 16:f2279b7602d3

Initial 2.00 commit
author Oleg Oshmyan <chortos@inbox.lv>
date Mon, 07 Jun 2010 23:36:52 +0000
parents
children ec6f1a132109
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/2.00/problem.py	Mon Jun 07 23:36:52 2010 +0000
@@ -0,0 +1,31 @@
+#!/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
\ No newline at end of file