ソースコード
WITH
Calc_MAX_SUB
AS
(
    SELECT
         USER_ID
        ,PROBLEM_ID
        ,ENTRY_ID
        ,SUBMITTED_AT
        ,STATUS
    FROM SUBMISSIONS
    WHERE ENTRY_ID IS NOT NULL AND STATUS = 'AC' AND CONTEST_ID = 2
    ORDER BY
         USER_ID
        ,PROBLEM_ID
        ,SUBMITTED_AT
)
,
Calc_MAX
AS
(
    SELECT
         USER_ID
        ,MAX(SUBMITTED_AT) AS MAX_AT
    FROM Calc_MAX_SUB
    GROUP BY
         USER_ID
)
,
Make_TABLE
AS
(
    SELECT 
         *
        ,CASE
            WHEN SUB.STATUS = 'AC' AND SUB.SUBMITTED_AT =  CM.MAX_AT THEN STRFTIME('%s',SUB.SUBMITTED_AT) - STRFTIME('%s',ENT.STARTED_AT) 
            WHEN SUB.STATUS = 'AC' AND SUB.SUBMITTED_AT <> CM.MAX_AT THEN 0 
            ELSE 300
         END AS EXAM_AT
    FROM SUBMISSIONS AS SUB
    LEFT JOIN ENTRIES AS ENT on SUB.USER_ID = ENT.USER_ID AND SUB.ENTRY_ID = ENT.ENTRY_ID  
    LEFT JOIN Calc_MAX AS CM on SUB.USER_ID = CM.USER_ID
    LEFT JOIN Calc_MAX_SUB AS MS on SUB.USER_ID = MS.USER_ID AND SUB.PROBLEM_ID = MS.PROBLEM_ID
    WHERE SUB.CONTEST_ID = 2 AND SUB.ENTRY_ID IS NOT NULL AND SUB.SUBMITTED_AT <= CM.MAX_AT AND MS.PROBLEM_ID IS NOT NULL
    ORDER BY
         SUB.USER_ID
        ,SUB.PROBLEM_ID
        ,SUB.SUBMITTED_AT
)
,
Ranking_TABLE
AS
(
    SELECT
         RANK() OVER (ORDER BY POINT DESC, EX_TIME, WRONG_ANS) AS RANK
        ,USER_ID
        ,POINT
        ,EX_TIME
        ,WRONG_ANS
    FROM
    (
        SELECT
             USER_ID
            ,SUM(POINT) AS POINT
            ,SUM(EXAM_AT) AS EX_TIME
            ,SUM(CASE WHEN STATUS = 'AC' THEN 0 ELSE 1 END) AS WRONG_ANS
        FROM Make_TABLE
        GROUP BY
             USER_ID
    )
)
SELECT * FROM Ranking_TABLE
WHERE POINT > 0
ORDER BY
     RANK
    ,WRONG_ANS
    ,USER_ID
;
提出情報
提出日時2024/05/31 09:50:50
コンテスト第3回 SQLコンテスト
問題順位計算
受験者satoru
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量85 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
85 MB
データパターン2
WA
85 MB