ソースコード
select
  rank() over(order by pt desc, ex_time asc) as RANK,
  user_id USER_ID,
  pt POINT,
  ex_time EX_TIME,
  was WRONG_ANS
FROM
(
  select
    entry.user_id,
    pt_time.pt,
    ifnull(penalty.was, 0) was,
    ifnull(penalty.penalty, 0) + strftime('%s', pt_time.lastac_at) - strftime('%s', started_at) as ex_time
  from
    entries entry
    inner join (
      select
        entry_id,
        user_id,
        max(submitted_at) lastac_at,
        sum(point) pt
      from
        submissions
      where
        contest_id = 2
        and status = 'AC'
        and entry_id is not null
      group by user_id, entry_id
      having sum(point) > 0
    ) pt_time
    on entry.user_id = pt_time.user_id and entry.entry_id = pt_time.entry_id
    left join (
      select
        s.user_id,
        count(1) was,
        count(1)*300 penalty
      from
        submissions s
        inner join (
          select
            user_id,
            problem_id,
            max(submitted_at) lasttime
          from submissions
          where
            status = 'AC'
            and contest_id = 2
            and entry_id is not null
          group by user_id, problem_id
        ) l
        on
          s.user_id = l.user_id
          and s.problem_id = l.problem_id
          and s.submitted_at < l.lasttime
      where
        contest_id = 2
        and status != 'AC'
        and entry_id is not null
      group by s.user_id
    ) penalty
    on entry.user_id = penalty.user_id
  where
    contest_id = 2
) master
order by RANK, WAS, USER_ID
;
提出情報
提出日時2022/10/19 21:39:32
コンテスト第3回 SQLコンテスト
問題順位計算
受験者espressivosubito
状態 (詳細)AC
(Accepted: 正答)
メモリ使用量97 MB
メッセージ
テストケース(通過数/総数)
2/2
状態
メモリ使用量
データパターン1
AC
96 MB
データパターン2
AC
97 MB