/** * Calculate the rank for a single team based on the cache tables */ function calcTeamRank($cdata, $teamid, $teamtotals, $jury = FALSE) { global $DB; if (empty($cdata)) { return; } $fdata = calcFreezeData($cdata); $cid = $cdata['cid']; // Use jury scoreboard when jury or final scoreboard should be displayed $tblname = $jury || $fdata['showfinal'] ? 'jury' : 'public'; $points = isset($teamtotals['points']) ? $teamtotals['points'] : 0; $totaltime = isset($teamtotals['totaltime']) ? $teamtotals['totaltime'] : 0; $sortorder = $DB->q('VALUE SELECT sortorder FROM team_category LEFT JOIN team USING (categoryid) WHERE teamid = %i', $teamid); // Number of teams that definitely ranked higher $better = $DB->q("VALUE SELECT COUNT(team.teamid)\n\t FROM rankcache_{$tblname} AS rc\n\t LEFT JOIN team USING (teamid)\n\t LEFT JOIN team_category USING (categoryid)\n\t WHERE cid = %i AND sortorder = %i AND enabled = 1\n\t AND (points > %i OR (points = %i AND totaltime < %i))", $cid, $sortorder, $points, $points, $totaltime); $rank = $better + 1; // Resolve ties based on latest correctness points, only necessary when we actually // solved at least one problem, so this list should usually be short if ($points > 0) { $tied = $DB->q("COLUMN SELECT team.teamid\n\t\t FROM rankcache_{$tblname} AS rc\n\t\t LEFT JOIN team USING (teamid)\n\t\t LEFT JOIN team_category USING (categoryid)\n\t\t WHERE cid = %i AND sortorder = %i AND enabled = 1\n\t\t AND points = %i AND totaltime = %i", $cid, $sortorder, $points, $totaltime); // All teams that are tied for this position, in most cases this will // only be the team we are finding the rank for, only retrieve rest of // the data when there are actual ties if (count($tied) > 1) { // initialize teamdata for each team $teamdata = array(); foreach ($tied as $tiedid) { $teamdata[$tiedid]['solve_times'] = array(); } // Get submission times for each of the teams $scoredata = $DB->q("SELECT teamid, totaltime\n\t\t\t FROM scorecache_{$tblname} AS sc\n\t\t\t LEFT JOIN problem p USING (probid)\n\t\t\t LEFT JOIN contestproblem cp USING (probid, cid)\n\t\t\t WHERE sc.cid = %i AND is_correct = 1\n\t\t\t AND allow_submit = 1 AND teamid IN (%Ai)", $cid, $tied); while ($srow = $scoredata->next()) { $teamdata[$srow['teamid']]['solve_times'][] = $srow['totaltime']; } // Now check for each team if it is ranked higher than $teamid foreach ($tied as $tiedid) { if ($tiedid == $teamid) { continue; } if (tiebreaker($teamdata[$tiedid], $teamdata[$teamid]) < 0) { $rank++; } } } } return $rank; }
/** * Outputs bulleted list of problem statements for this contest */ function putProblemTextList() { global $cid, $cdata, $DB; $fdata = calcFreezeData($cdata); if (!have_problemtexts()) { echo "<p class=\"nodata\">No problem texts available for this contest.</p>\n\n"; } elseif (!$fdata['cstarted']) { echo "<p class=\"nodata\">Problem texts will appear here at contest start.</p>\n\n"; } else { // otherwise, display list $res = $DB->q('SELECT probid,shortname,name,color,problemtext_type FROM problem INNER JOIN contestproblem USING (probid) WHERE cid = %i AND allow_submit = 1 AND problemtext_type IS NOT NULL ORDER BY shortname', $cid); if ($res->count() > 0) { echo "<ul>\n"; while ($row = $res->next()) { print '<li> ' . '<img src="../images/' . urlencode($row['problemtext_type']) . '.png" alt="' . htmlspecialchars($row['problemtext_type']) . '" /> <a href="problem.php?id=' . urlencode($row['probid']) . '">' . 'Problem ' . htmlspecialchars($row['shortname']) . ': ' . htmlspecialchars($row['name']) . "</a></li>\n"; } echo "</ul>\n"; } } }
<?php /** * Part of the DOMjudge Programming Contest Jury System and licenced * under the GNU GPL. See README and COPYING for details. */ require 'init.php'; $title = specialchars($teamdata['name']); require LIBWWWDIR . '/header.php'; // Don't use HTTP meta refresh, but javascript: otherwise we cannot // cancel it when the user starts editing the submit form. This also // provides graceful degradation without javascript present. $refreshtime = 30; $submitted = @$_GET['submitted']; $fdata = calcFreezeData($cdata); $langdata = $DB->q('KEYTABLE SELECT langid AS ARRAYKEY, name, extensions FROM language WHERE allow_submit = 1'); echo "<script type=\"text/javascript\">\n<!--\n"; if ($fdata['cstarted']) { $probdata = $DB->q('TABLE SELECT probid, shortname, name FROM problem INNER JOIN contestproblem USING (probid) WHERE cid = %i AND allow_submit = 1 ORDER BY shortname', $cid); putgetMainExtension($langdata); echo "function getProbDescription(probid)\n{\n"; echo "\tswitch(probid) {\n"; foreach ($probdata as $probinfo) { echo "\t\tcase '" . specialchars($probinfo['shortname']) . "': return '" . specialchars($probinfo['name']) . "';\n"; } echo "\t\tdefault: return '';\n\t}\n}\n\n"; }
/** * Outputs bulleted list of problem names for this contest, * with links to problem statement text and/or sample testcase(s) * when available. */ function putProblemTextList() { global $cid, $cdata, $DB; $fdata = calcFreezeData($cdata); if (!$fdata['cstarted']) { echo "<p class=\"nodata\">Problem texts will appear here at contest start.</p>\n\n"; } else { // otherwise, display list $res = $DB->q('SELECT probid,shortname,name,color,problemtext_type,MAX(sample) AS numsamples FROM problem INNER JOIN testcase USING(probid) INNER JOIN contestproblem USING (probid) WHERE cid = %i AND allow_submit = 1 GROUP BY probid ORDER BY shortname', $cid); if ($res->count() > 0) { echo "<ul>\n"; while ($row = $res->next()) { print '<li><strong> Problem ' . specialchars($row['shortname']) . ': ' . specialchars($row['name']) . "</strong><br />\n"; if (isset($row['problemtext_type'])) { print '<img src="../images/' . urlencode($row['problemtext_type']) . '.png" alt="' . specialchars($row['problemtext_type']) . '" /> <a href="problem.php?id=' . urlencode($row['probid']) . '">' . 'problem statement</a><br />'; } $i = 1; if (!empty($row['numsamples'])) { $samples = $DB->q('COLUMN SELECT testcaseid FROM testcase WHERE probid = %i AND sample = 1 ORDER BY testcaseid ASC', $row['probid']); foreach ($samples as $id) { print '<img src="../images/b_save.png" alt="download" /> '; print '<a href="problem.php?id=' . urlencode($row['probid']) . '&testcase=' . urlencode($i) . '&type=in">sample input</a> | '; print '<a href="problem.php?id=' . urlencode($row['probid']) . '&testcase=' . urlencode($i) . '&type=out">sample output</a>'; print "<br />"; ++$i; } } print "<br /></li>\n"; } echo "</ul>\n"; } else { echo "<p class=\"nodata\">No problem texts available for this contest.</p>\n\n"; } } }