ソースコード

WITH data AS (
    SELECT
        *
    FROM ENTRIES
    JOIN SUBMISSIONS
    USING (CONTEST_ID, USER_ID, ENTRY_ID)
    WHERE
    ENTRY_ID IS NOT NULL
    AND CONTEST_ID = 2
), points AS (
    SELECT
        USER_ID,
        SUM(POINT) POINT
    FROM data
    GROUP BY USER_ID
    HAVING POINT > 0
), max_time AS (
    SELECT
        USER_ID,
        MAX(SUBMITTED_AT) MAX_SUBMITTED_AT
    FROM data
    WHERE STATUS = "AC"
    GROUP BY USER_ID
), ac AS (
    SELECT
        USER_ID,
        MAX(strftime('%s', MAX_SUBMITTED_AT) - strftime('%s', STARTED_AT)) AS TIME
    FROM data
    JOIN max_time
    USING (USER_ID)
    WHERE STATUS = "AC"
    GROUP BY USER_ID
), max_time_prob AS (
    SELECT
        USER_ID,
        PROBLEM_ID,
        MAX(SUBMITTED_AT) MAX_SUBMITTED_AT
    FROM data
    WHERE STATUS = "AC"
    GROUP BY USER_ID, PROBLEM_ID
), wrong AS (
    SELECT
        USER_ID,
        COUNT(CASE WHEN SUBMITTED_AT < MAX_SUBMITTED_AT THEN 1 END) AS WRONG_ANS
    FROM data
    JOIN max_time_prob
    USING (USER_ID, PROBLEM_ID)
    WHERE STATUS != "AC"
    GROUP BY USER_ID
)

SELECT

RANK() OVER (ORDER BY POINT DESC, TIME + 300 * WRONG_ANS) RANK,
USER_ID,
POINT,
TIME + 300 * IFNULL(WRONG_ANS, 0) AS EX_TIME,
IFNULL(WRONG_ANS, 0) WRONG_ANS
FROM points
JOIN ac
USING (USER_ID)
LEFT OUTER JOIN wrong
USING (USER_ID)
ORDER BY
RANK,
WRONG_ANS,
USER_ID


提出情報
提出日時2022/10/20 00:47:12
コンテスト第3回 SQLコンテスト
問題順位計算
受験者mugenen
状態 (詳細)WA
(Wrong Answer: 誤答)
メモリ使用量101 MB
メッセージ
テストケース(通過数/総数)
0/2
状態
メモリ使用量
データパターン1
WA
101 MB
データパターン2
WA
98 MB