Python Discriminated against again!!

Revision en1, by Binary_Crusader2503, 2025-01-04 22:40:00

In the contest Hello 2025 Question 2 (https://codeforces.net/contest/2057/problem/B).I encountered an interesting issue where the same logic, when implemented in Python, resulted in a Time Limit Exceeded (TLE) error, while the C++ version worked flawlessly within the constraints. This raises an important question about the fairness of using Python in competitive programming. Python, being an interpreted language with slower I/O operations and dynamic typing, tends to be slower than C++, especially when handling large inputs within strict time limits. Contest organizers should ensure that Python solutions are adequately supported by adjusting time limits and testing across all allowed languages to ensure fairness. If Python is offered as a valid contest language, it’s important to apply time multipliers, and set reasonable input sizes that account for Python’s slower performance. As a participant, while optimizing my solution is my responsibility, it’s crucial for contest organizers to consider these language-specific challenges and create a level playing field for all competitors. My Python Code from collections import Counter from collections import Counter for j in range(int(input())): n,k=map(int, input().split()) a=list(map(int, input().split())) d={} t=[] if k==n: print(1) continue if k==0: print(len(set(a))) continue for i in a: if i in d: d[i]+=1 else: d[i]=1 for i in d: t.append(d[i])
t.sort()
for i in range(len(t)): if k-t[i]<0: print(len(t)-i) break elif k-t[i]==0: print(len(t)-i-1) break else: k-=t[i] Accepted C++ Code

include

include

include

include

include

using namespace std;

int main() { int t; cin >> t; while (t--) { int n, k; cin >> n >> k; vector a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; }

map<int, int> d;
    vector<int> t;

    if (k == n) {
        cout << 1 << endl;
        continue;
    }
    if (k == 0) {
        set<int> unique(a.begin(), a.end());
        cout << unique.size() << endl;
        continue;
    }

    for (int i : a) {
        d[i]++;
    }

    for (auto &pair : d) {
        t.push_back(pair.second);
    }

    sort(t.begin(), t.end());

    for (size_t i = 0; i < t.size(); ++i) {
        if (k - t[i] < 0) {
            cout << t.size() - i << endl;
            break;
        } else if (k - t[i] == 0) {
            cout << t.size() - i - 1 << endl;
            break;
        } else {
            k -= t[i];
        }
    }
}
return 0;

}

I hope that the organizer will atlest try to compensate for this.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English Binary_Crusader2503 2025-01-04 23:23:03 38
en2 English Binary_Crusader2503 2025-01-04 22:47:27 1854
en1 English Binary_Crusader2503 2025-01-04 22:40:00 3090 Initial revision (published)