Help in this problem

Chef Award | CodeChef

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
// #pragma GCC optimize "trapv"

#define ll long long 
#define lld long double

int main() {
	// your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n;
        cin>>n;
        int arr[n],mark[1001]={0};
        
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            mark[arr[i]]++;
        }
    
        
        ll ans=0;
        
        for(int i=n-1;i>=0;i--)
        {
            int x=arr[i];
            
            for(int j=1;j<x;j++)
            ans+=mark[j];
            
            mark[x]--;
            
            //cout<<ans<<"\n";
        }
        cout<<ans;
    }
}

For which TC this will fail?
@ssjgz

Check out the editorial here

I am asking about any TC for which this code will fail. I have seen editorial approach

I can’t find a single one, and I’ve tried 1000s.

The only things I can think of are:

  • The constraints are wrong, and there are testcases with marks > 1000; or
  • the fact that you are not adding a new-line after your output is causing the failure (but I thought the OJ was mostly whitespace-insensitive).
1 Like

Tried both
Increased size of mark to 1e7 and printed a new line after output. But it didn’t work.

1 Like

Might also be worth trying removing the pragmas.

1 Like

Didn’t worked.

While O(n^2) sol passes in 0.1 sec
Solution: 44352914 | CodeChef

No idea, then :man_shrugging: Try using endl, and try checking for overflow (Simple Trick to Detect Integer Overflow (C/C++)), but I’m really clutching at straws, here :frowning:

1 Like

This might answer- CodeChef: Practical coding for everyone

3 Likes

lol - why didn’t I think of that XD Well done!

What is it with third-party contests and broken testcases??

2 Likes