ソースコード
with timetbl as (
    select 
        su.user_id as USER_ID,
        su.entry_id,
        su.problem_id,
        su.point,
        strftime('%s', submitted_at) - strftime('%s', en.started_at) as EX_TIME,
        submitted_at as maxtime 
    from submissions as su 
    inner join entries as en 
    on su.entry_id=en.entry_id
    and su.contest_id=en.contest_id
    where su.status='AC' 
    and su.contest_id=2 
    and su.entry_id is not null
    group by su.entry_id,problem_id 
),tbl as (
    select 
        timetbl.USER_ID,
        timetbl.problem_id,
        max(timetbl.EX_TIME) as ex_time,
        sum(iif(status='WA',1,0)) as WRONG_ANS  
    from timetbl 
    inner join submissions as su 
    on timetbl.entry_id=su.entry_id 
    and timetbl.problem_id=su.problem_id 
    where su.submitted_at<timetbl.maxtime 
    and su.contest_id=2 
    and su.entry_id is not null 
    group by timetbl.entry_id,timetbl.problem_id
    order by timetbl.user_id 
),watotal as (
    select 
        user_id,
        sum(wrong_ans) as WRONG_ANS
    from tbl
    group by user_id
)
,actotal as (
    select 
        USER_ID,
        sum(point) as POINT,
        max(ex_time) as EX_TIME
    from timetbl
    group by user_id
    having sum(point)>0
)
select 
    rank() over(order by point desc,EX_TIME+300*ifnull(wrong_ans,0)) as RANK ,
    actotal.USER_ID,
    POINT,
    EX_TIME+300*ifnull(wrong_ans,0) as EX_TIME,
    ifnull(WRONG_ANS ,0) as WRONG_ANS 
from actotal 
left outer join watotal
on actotal.user_id=watotal.user_id
order by rank,wrong_ans,actotal.user_id;
提出情報
提出日時2024/12/22 21:01:59
コンテスト第3回 SQLコンテスト
問題順位計算
受験者kate
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量86 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
AC
86 MB