How to get the number of pretests in a codeforces problem?
Difference between en3 and en4, changed 225 character(s)
Is there any way to get the number of pretests of a problem?↵

I tried using this code↵

<spoiler summary="Code">↵
```javascript↵
const pretest_passed_verdicts={↵
    SKIPPED:1,↵
    CHALLENGED:1, // aka hacked↵

    0:0}↵

function getPassedTestCount(x){↵
    return x.passedTestCount↵
}↵

$.get('https://codeforces.com/api/contest.status?contestId=566&from=1&count=1000000',data=>{↵
    for(let problemID of new Set(data.result.map(x=>x.problem.index))){↵
        let problemResult=data.result.filter(x=>↵
            x.problem.index==problemID&&↵
            x.author.participantType=="CONTESTANT"↵
        )↵
        let minPretestCount,maxPretestCount↵

        let s1=problemResult.filter(x=>↵
            pretest_passed_verdicts[x.verdict]↵
        )↵
        if(s1.length!=0){↵
            minPretestCount=Math.min(...s1.map(getPassedTestCount))↵
            maxPretestCount=Math.max(...s1.map(getPassedTestCount))↵
            if(minPretestCount!=maxPretestCount)↵
                throw new Error()↵
        }else{↵
            minPretestCount=1+Math.max(...↵
                problemResult.filter(↵
                    // x=>x.testset=="PRETESTS"&&wrong_verdicts[x.verdict]↵
                    // cannot be "skipped" -> must fail on pretest↵
                    x=>x.testset=="PRETESTS"↵
                ).map(getPassedTestCount)↵
            )↵
            maxPretestCount=Math.min(...↵
                problemResult.filter(↵
                    x=>x.testset=="TESTS"↵
                ).map(getPassedTestCount)↵
            )↵
        }↵
        console.log(problemID,minPretestCount,maxPretestCount)↵
    }↵
})↵
```↵
</spoiler>↵

(fetch every submissions, check if there's any skipped/hacked solution then the number of pretest is the number of passed test of that submission, otherwise estimate the number by getting number of passed tests of solutions that fail on pretests/main tests of contestants)↵

However there 
are someis a problems:↵

* It's not possible if there's not enough submission for that problem. (For instance, running the code above says that there are at least 1 and at most 138 pretests for problem 566E)↵

And some problems that have workaround:↵

* It's slow. (This can be partially avoided by fetching only solutions in contest, given that there are currently 19528 submissions but only 3585 in-contest ones for #566; and store fetched result with `GM_getValue/GM_setValue` or `GM.getValue/GM.setValue` &mdash; so it's necessary to download the data only once for each contest)↵
* The code will not work when there are cheaters (for example [this submission](https://codeforces.com/contest/1221/submission/60879848) is listed as "skipped" but there's a "wrong answer" test, however it's not because the user submit another one but it's likely because the user cheated, according to https://codeforces.com/blog/entry/58038) This can be work around by fetching the submission page to see if there's any failed test (there's no indication in the [API result](https://codeforces.com/api/contest.status?contestId=1221&from=1&count=1000000&handle=1999mukulrai).↵

--------↵

Background: I'm trying to fix the [userscript](https://codeforces.com/blog/entry/61682#comment-545123) that displays only pretest verdict in virtual participation. A huge bug is that it assumes that double clicking an entry in the standing table will show `[pretests]` or `[main tests]` depends on whether the test is a pretest or a main test. However it isn't the case, as can be seen in https://codeforces.com/contest/566/standings (turn on "show unofficial", then double click the entry for problem C of user `hogloid`, you can see "Wrong answer on test 1 [main tests]", which is obviously wrong.↵
 

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en12 English z4120 2019-12-01 13:32:15 14753
en11 English z4120 2019-11-10 10:50:22 1527
en10 English z4120 2019-10-31 10:01:17 41
en9 English z4120 2019-10-31 09:51:58 4454 Fix small bug, rewrite post
en8 English z4120 2019-10-26 18:28:19 130
en7 English z4120 2019-10-26 18:21:49 3536 Fix userscript
en6 English z4120 2019-10-15 17:00:39 16469
en5 English z4120 2019-10-07 19:48:43 244
en4 English z4120 2019-10-07 19:35:09 225 New workaround for a problem
en3 English z4120 2019-10-05 16:45:13 583
en2 English z4120 2019-10-05 12:48:27 18 Add code formatting
en1 English z4120 2019-10-05 08:03:32 2964 Initial revision (published)