ソースコード
WITH B AS (
SELECT
  S.*
 ,E.STARTED_AT
FROM ENTRIES E
JOIN SUBMISSIONS S
  ON E.ENTRY_ID = S.ENTRY_ID
WHERE E.CONTEST_ID = 2
  AND STATUS = 'AC' )
, T AS (
SELECT
  USER_ID
 ,MAX(strftime('%s', SUBMITTED_AT) - strftime('%s', STARTED_AT)) TIME
FROM B
GROUP BY USER_ID)

SELECT
  RANK() OVER (ORDER BY POINT DESC, EX_TIME) RANK
 ,*
FROM (
SELECT
  A.USER_ID
 ,POINT
 ,T.TIME + (ifnull(A.WRONG_ANS, 0) * 300) EX_TIME
 ,WRONG_ANS
FROM (
SELECT
  USER_ID
 ,SUM(POINT) POINT
 ,SUM(WRONG_ANS) WRONG_ANS
FROM (
SELECT
  B.PROBLEM_ID
 ,B.USER_ID
 ,B.POINT
 ,ifnull(E.CNT, 0) WRONG_ANS
FROM B
LEFT JOIN (
  SELECT S.PROBLEM_ID, S.USER_ID, COUNT(*) CNT
  FROM SUBMISSIONS S
  JOIN (
    SELECT PROBLEM_ID, USER_ID, MAX(SUBMITTED_AT) SUBMITTED_AT
    FROM SUBMISSIONS
    WHERE CONTEST_ID = 2 AND STATUS = 'AC' AND ENTRY_ID IS NOT NULL
    GROUP BY PROBLEM_ID, USER_ID
  ) S2
  ON   S.PROBLEM_ID = S2.PROBLEM_ID
   AND S.USER_ID = S2.USER_ID
   AND S.SUBMITTED_AT < S2.SUBMITTED_AT
  WHERE S.CONTEST_ID = 2 AND S.STATUS <> 'AC' AND ENTRY_ID IS NOT NULL
  GROUP BY S.PROBLEM_ID, S.USER_ID
) E
ON   B.PROBLEM_ID = E.PROBLEM_ID
 AND B.USER_ID = E.USER_ID
) A
GROUP BY USER_ID
HAVING SUM(POINT) > 0
) A
JOIN T ON A.USER_ID = T.USER_ID
)
ORDER BY 1, WRONG_ANS, USER_ID
提出情報
提出日時2022/10/19 18:05:22
コンテスト第3回 SQLコンテスト
問題順位計算
受験者mine
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量105 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
105 MB
データパターン2
WA
90 MB