Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created April 28, 2010 04:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dtinth/381747 to your computer and use it in GitHub Desktop.
Save dtinth/381747 to your computer and use it in GitHub Desktop.
<?php
$task = $argv[1];
$num = intval($argv[2]);
$code = escapeshellarg($argv[3]);
@unlink ('/tmp/ao');
$cc = 'gcc';
`$cc -lm $code -o /tmp/ao`;
function s($a) {
$a = str_replace("\r\n", "\n", $a);
$a = str_replace("\r", "\n", $a);
return trim($a);
}
$xx = '';
for ($i = 1; $i <= $num; $i ++) {
$start = microtime(true);
$out = `cat $task/$i.in | /tmp/ao`;
$end = microtime(true);
$check = file_get_contents($task . '/' . $i . '.sol');
if ($end - $start > 0.2) {
echo 'T';
} else if (s($out) != s($check)) {
echo '-';
} else {
echo 'P';
}
$xx .= "\nTestcase #$i, time usage: " . sprintf("%5.3f", $end - $start);
}
echo "\n$xx\n\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment