ソースコード
with penalty as (
    select
        e.USER_ID as USER_ID,
        sum(
            case when s.SUBMITTED_AT < (
                select max(s2.SUBMITTED_AT)
                from SUBMISSIONS s2
                where s2.ENTRY_ID is not null and s2.ENTRY_ID = s.ENTRY_ID and s2.PROBLEM_ID = s.PROBLEM_ID and s2.CONTEST_ID = s.CONTEST_ID and s2.STATUS = 'AC' 
            )
            then 1
            else 0
            end
        ) as WRONG_ANS
    from ENTRIES e
    inner join
        SUBMISSIONS s
        on
            s.ENTRY_ID = e.ENTRY_ID
            and
            s.CONTEST_ID = e.CONTEST_ID
    where
        e.CONTEST_ID = 2
    group by
        e.USER_ID,
        s.PROBLEM_ID
),
score_and_time as (
    select
        e.USER_ID as USER_ID,
        sum(s.POINT) as POINT,
        max(s.SUBMITTED_AT) as LAST_SUBMITTED_AT,
        e.STARTED_AT as STARTED_AT
    from ENTRIES e
    inner join
        SUBMISSIONS s
        on s.ENTRY_ID = e.ENTRY_ID
    where
        e.CONTEST_ID = 2
        and
        s.STATUS = 'AC'
        and
        s.ENTRY_ID is not null
    group by
        e.USER_ID
)
select
    rank() over (order by score_and_time.POINT desc, STRFTIME('%s', score_and_time.LAST_SUBMITTED_AT) - STRFTIME('%s', score_and_time.STARTED_AT) + (300 * sum(penalty.WRONG_ANS))) as RANK,
    penalty.USER_ID as USER_ID,
    score_and_time.POINT as POINT,
    STRFTIME('%s', score_and_time.LAST_SUBMITTED_AT) - STRFTIME('%s', score_and_time.STARTED_AT) + (300 * sum(penalty.WRONG_ANS)) as EX_TIME,
    sum(penalty.WRONG_ANS) as WRONG_ANS
from
    penalty
inner join
    score_and_time
    on score_and_time.USER_ID = penalty.USER_ID
group by penalty.USER_ID
having score_and_time.POINT <> 0
order by
    RANK,
    WRONG_ANS,
    USER_ID;
提出情報
提出日時2024/07/10 20:14:50
コンテスト第3回 SQLコンテスト
問題順位計算
受験者tofu
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
86 MB
データパターン2
WA
85 MB