ソースコード
WITH T1 AS(
    SELECT
        USER_ID,
        PROBLEM_ID,
        MAX(POINT) AS POINT,
        MIN(SUBMITTED_AT) AS AC_TIME
    FROM
        SUBMISSIONS
    WHERE
        CONTEST_ID = 2
        AND ENTRY_ID IS NOT NULL
        AND STATUS = 'AC'
    GROUP BY
        USER_ID,
        PROBLEM_ID
),
T2 AS(
    SELECT
        USER_ID,
        MAX(AC_TIME) AS LAST_AC,
        SUM(POINT) AS POINT
    FROM
        T1
    GROUP BY
        USER_ID
),
T3 AS(
    SELECT
        SUBMISSIONS.USER_ID,
        MAX(T2.POINT) AS POINT,
        SUM(
            CASE
                WHEN STATUS != 'AC' AND AC_TIME IS NOT NULL AND SUBMITTED_AT < AC_TIME THEN 300
                ELSE 0
            END
        ) + STRFTIME('%s', LAST_AC) - STRFTIME('%s', STARTED_AT) AS EX_TIME,
        SUM(
            CASE
                WHEN STATUS != 'AC' AND AC_TIME IS NOT NULL AND SUBMITTED_AT < AC_TIME THEN 1
                ELSE 0
            END
        ) AS WRONG_ANS
    FROM
        SUBMISSIONS
        INNER JOIN
            ENTRIES ON ENTRIES.USER_ID = SUBMISSIONS.USER_ID,
            T1 ON T1.USER_ID = SUBMISSIONS.USER_ID AND T1.PROBLEM_ID = SUBMISSIONS.PROBLEM_ID,
            T2 ON T2.USER_ID = SUBMISSIONS.USER_ID
    WHERE
        T2.POINT IS NOT NULL
        AND SUBMISSIONS.CONTEST_ID = 2
        AND SUBMISSIONS.ENTRY_ID IS NOT NULL
    GROUP BY
        SUBMISSIONS.USER_ID
)
SELECT
    RANK() OVER(ORDER BY POINT DESC, EX_TIME ASC) AS RANK,
    USER_ID,
    POINT,
    EX_TIME,
    WRONG_ANS
FROM
    T3
ORDER BY
    RANK ASC,
    WRONG_ANS ASC,
    USER_ID ASC
提出情報
提出日時2023/08/25 15:32:30
コンテスト第3回 SQLコンテスト
問題順位計算
受験者tabr
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量80 MB
メッセージ
テストケース(通過数/総数)
1/2
状態
メモリ使用量
データパターン1
AC
80 MB
データパターン2
WA
80 MB