ソースコード
WITH TMP AS(
    SELECT
        s.SUBMIT_ID AS SUBMIT_ID
        ,s.CONTEST_ID AS CONTEST_ID
        ,s.PROBLEM_ID AS PROBLEM_ID
        ,s.USER_ID AS USER_ID
        ,s.ENTRY_ID AS ENTRY_ID
        ,s.SUBMITTED_AT AS SUBMITTED_AT
        ,e.STARTED_AT AS STARTED_AT
        ,s.STATUS AS STATUS
        ,s.POINT AS POINT
    FROM SUBMISSIONS s INNER JOIN ENTRIES e USING(ENTRY_ID)
)
,TOTAL_POINT AS(
    SELECT
        CONTEST_ID
        ,USER_ID
        ,SUM(POINT) AS POINT
    FROM TMP
    WHERE STATUS = 'AC'
    GROUP BY
        CONTEST_ID
        ,USER_ID
)
,TIME AS(
    SELECT
        CONTEST_ID
        ,USER_ID
        ,strftime('%s', MAX(SUBMITTED_AT)) - strftime('%s', STARTED_AT) AS TOTAL_TIME
    FROM TMP
    WHERE STATUS = 'AC'
    GROUP BY
        CONTEST_ID
        ,USER_ID
)
,AC_TIMER AS(
    SELECT
        CONTEST_ID
        ,PROBLEM_ID
        ,USER_ID
        ,MAX(SUBMITTED_AT) AS AC_TIME
    FROM TMP
    WHERE STATUS ='AC'
    GROUP BY
        CONTEST_ID
        ,PROBLEM_ID
        ,USER_ID
)

,AW_COUNT AS(
    SELECT
        t.CONTEST_ID
        ,t.USER_ID
        ,SUM(CASE WHEN t.STATUS != 'AC' THEN 1 ELSE 0 END) AS WRONG_ANS
    FROM
        TMP t INNER JOIN AC_TIMER a 
        ON t.CONTEST_ID = a.CONTEST_ID
            AND t.PROBLEM_ID = a.PROBLEM_ID
            AND t.USER_ID = a.USER_ID
            AND t.SUBMITTED_AT <= a.AC_TIME
    GROUP BY 
        t.CONTEST_ID
        ,t.USER_ID
)

SELECT
    RANK() OVER(ORDER BY POINT DESC, TOTAL_TIME + WRONG_ANS * 300, WRONG_ANS) AS RANK
    ,USER_ID
    ,POINT
    ,TOTAL_TIME + WRONG_ANS * 300 AS EX_TIME
    ,WRONG_ANS
FROM
TOTAL_POINT
NATURAL JOIN
TIME
NATURAL JOIN
AW_COUNT
WHERE CONTEST_ID = 2 AND POINT > 0
ORDER BY 1,5,2
提出情報
提出日時2023/02/16 14:01:12
コンテスト第3回 SQLコンテスト
問題順位計算
受験者mott
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量80 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
80 MB
データパターン2
WA
80 MB