結果

問題 No.447 ゆきこーだーの雨と雪 (2)
ユーザー papinianuspapinianus
提出日時 2016-12-01 23:32:51
言語 PHP
(8.3.4)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 2,822 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 31,056 KB
実行使用メモリ 34,444 KB
最終ジャッジ日時 2024-11-27 16:43:53
合計ジャッジ時間 5,244 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
31,128 KB
testcase_01 AC 39 ms
30,928 KB
testcase_02 AC 39 ms
30,880 KB
testcase_03 AC 87 ms
30,948 KB
testcase_04 AC 68 ms
31,340 KB
testcase_05 AC 198 ms
32,780 KB
testcase_06 AC 216 ms
34,188 KB
testcase_07 AC 192 ms
31,500 KB
testcase_08 AC 138 ms
32,272 KB
testcase_09 AC 272 ms
33,676 KB
testcase_10 AC 49 ms
31,212 KB
testcase_11 AC 80 ms
31,108 KB
testcase_12 AC 88 ms
31,760 KB
testcase_13 AC 243 ms
32,656 KB
testcase_14 AC 326 ms
33,292 KB
testcase_15 AC 90 ms
31,272 KB
testcase_16 AC 47 ms
31,500 KB
testcase_17 AC 75 ms
31,212 KB
testcase_18 AC 43 ms
30,820 KB
testcase_19 AC 254 ms
34,444 KB
testcase_20 AC 330 ms
33,744 KB
testcase_21 AC 83 ms
31,376 KB
testcase_22 AC 91 ms
31,176 KB
testcase_23 AC 118 ms
31,008 KB
testcase_24 AC 280 ms
32,784 KB
testcase_25 AC 312 ms
33,804 KB
testcase_26 AC 181 ms
31,500 KB
testcase_27 AC 161 ms
31,500 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
$problemCount = trim(fgets(STDIN));
$ranks = array_fill(0, $problemCount,1);
$problems = explode(' ', trim(fgets(STDIN)));
$posts = trim(fgets(STDIN));
$scores = [];
$board = new scoreboard();

for(;$posts;$posts--)
{
    list($name, $problemCode) = explode(' ', trim(fgets(STDIN)));
    if(!isset($scores[$name]))
    {
        $scores[$name] = new scorenote($name, $problemCount);
    }
    $problemID = getID($problemCode);
    $stars = $problems[$problemID];
    $rank = $ranks[$problemID]++;
    $scores[$name]->setScore($problemID, calcScore($stars, $rank));
    $board->upsert($name, $scores[$name]->getSum());
}
foreach($board->getOrder() as $i => $name)
{
    echo ($i+1).' '.$scores[$name]->toString().PHP_EOL;
}


function getID($char)
{
    $alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ?';
    return strpos($alpha, $char);
}

function calcScore($stars, $rank)
{
    return floor((50 * $stars) + ((50 * $stars) / (0.8 + (0.2 * $rank))));
}

class scoreboard
{
    private $table;
    private $members;
    
    public function __construct()
    {
        $this->members = [];
        $this->table = [];
    }
    
    public function upsert($name, $sum)
    {
        if($this->inMember($name))
        {
            array_splice($this->table, $this->members[$name], 1);
        }
        else
        {
            $this->members[$name] = count($this->members);
        }
        for($i = $this->members[$name];$i;$i--)
        {
            $prev = $i - 1;
            if($this->table[$prev][1] >= $sum)
            {
                break;
            }
        }
        array_splice($this->table, $i ,0, [[$name, $sum]]);
        $tableRows = count($this->table);
        for(;$i < $tableRows; $i++)
        {
            $this->members[$this->table[$i][0]] = $i;
        }
    }
    
    public function getOrder()
    {
        $ret = [];
        foreach($this->table as $row)
        {
            $ret[] = $row[0];
        }
        return $ret;
    }
    
    private function inMember($name)
    {
        return isset($this->members[$name]);
    }
}

class scorenote
{
    private $name;
    private $scores;
    private $sum;
    
    public function __construct($name, $count)
    {
        $this->name = $name;
        $this->scores = array_fill(0, $count, 0);
        $this->sum = 0;
    }
    
    public function getName()
    {
        return $this->name;
    }
    public function getSum()
    {
        return $this->sum;
    }
    
    public function toString()
    {
        $res = $this->name.' ';
        foreach($this->scores as $score)
        {
            $res .= $score.' ';
        }
        $res .= $this->sum;
        return $res;
    }
    
    public function setScore($problemId, $score)
    {
        $this->scores[$problemId] = $score;
        $this->sum += $score;
    }
}
0