Submission #280307
Source Code Expand
<?php
// {{{ get input module
// debug input file name
define('DEBUG_FN', 'input.txt');
/* first module start (setup $input) */
if(file_exists(DEBUG_FN))
{
$inputs = explode("\n---\n", file_get_contents(DEBUG_FN));
define('DEBUG', TRUE);
} else
{
$inputs = array(file_get_contents('php://stdin'));
define('DEBUG', FALSE);
}
foreach ($inputs as $i => $input) {
if (DEBUG) {
echo "\n----- {$i} -----\n";
$time_start = microtime(true);
}
solve($input);
if (DEBUG) {
$time_end = microtime(true);
$time = $time_end - $time_start;
echo sprintf("\n[%.5fms]", $time * 1000);
}
}
// }}} -end
function solve($input) {
$lines = partition_line($input);
list($nn, $X) = explode(' ', $lines[0]);
$nums = explode(' ', $lines[1]);
$sum = 0;
foreach ($nums as $i => $n) {
if (($X >> $i) & 1) {
$sum += $n;
}
}
echo $sum;
}
// {{{ funcs
/*
*---------------------------------------------------------------
* funcs
*---------------------------------------------------------------
*/
/**
* 0 only debug output
*/
function unset_multi(array $arr, array $unset_keys, $rename_key = FALSE)
{
foreach ($unset_keys as $key)
{
unset($arr[$key]);
}
if ($rename_key)
$arr = array_values($arr);
return $arr;
}
function partition_word ($line)
{
return explode(" ", rtrim($line));
}
function partition_line ($text)
{
$text = rtrim(gather_linereturn (rtrim($text)));
return explode("\n", $text);
}
function partition_word_all($text)
{
$lines = partition_line($text);
$values = array();
foreach ($lines as $line)
{
$values[] = partition_word($line);
}
return $values;
}
function gather_linereturn($str)
{
return str_replace(array("\r\n", "\r"), "\n", $str);
}
function pc_permute($items, &$results = array(), $perms = array()) {
if (empty($items)) {
// print join(' ', $perms) . "\n";
$results[] = $perms;
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems, $results, $newperms);
}
}
}
function trim_returns($str) {
return str_replace(array("\r\n", "\r", "\n"), "", $str);
}
// }}} --end
Submission Info
Submission Time |
|
Task |
B - 価格の合計 |
User |
elzup |
Language |
PHP (PHP 5.3.10) |
Score |
0 |
Code Size |
2553 Byte |
Status |
WA |
Exec Time |
57 ms |
Memory |
4088 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt |
All |
subtask0_sample01.txt, subtask0_sample02.txt, subtask0_sample03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_sample01.txt |
WA |
54 ms |
4028 KB |
subtask0_sample02.txt |
WA |
51 ms |
4028 KB |
subtask0_sample03.txt |
WA |
52 ms |
4088 KB |
subtask1_01.txt |
WA |
53 ms |
4024 KB |
subtask1_02.txt |
WA |
53 ms |
4020 KB |
subtask1_03.txt |
WA |
52 ms |
4020 KB |
subtask1_04.txt |
WA |
53 ms |
4020 KB |
subtask1_05.txt |
WA |
53 ms |
4020 KB |
subtask1_06.txt |
WA |
52 ms |
4028 KB |
subtask1_07.txt |
WA |
53 ms |
4028 KB |
subtask1_08.txt |
WA |
53 ms |
4028 KB |
subtask1_09.txt |
WA |
52 ms |
4020 KB |
subtask1_10.txt |
WA |
53 ms |
4024 KB |
subtask1_11.txt |
WA |
52 ms |
4024 KB |
subtask1_12.txt |
WA |
52 ms |
4028 KB |
subtask1_13.txt |
WA |
57 ms |
4024 KB |
subtask1_14.txt |
WA |
52 ms |
4084 KB |
subtask1_15.txt |
WA |
53 ms |
4020 KB |
subtask1_16.txt |
WA |
51 ms |
4020 KB |
subtask1_17.txt |
WA |
52 ms |
4020 KB |