NPAIRS - Editorial

@prit_esh_07 bro why cant we post in this discussion

bro can u explain this part
Thanks!

yeah sure !
That is a simplification of nC2 , where n is the number of occurrences of a value X. we just need to find how many pairs can be made with X number of options.

so, nC2 translates to
n!/((2!)*((n-2)!))
which on solving further gives : n(n-1)/2*

Hope it is was a clear explanation for answering your question.

Mine approach :v:

#define NDEBUG
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using pi = pair<int, int>;
 
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define sz(x) (int)(x).size()
#define ins insert
#define MOD 1000000007t
#define endl '\n'
#define all(x) begin(x), end(x)
#define desc greater<int>()
#define rall(x) rbegin(x), rend(x)
#define error 1e-6
#define rep(i, a, b) for(__typeof(b) i=(a-(a>b));i!=(b-(a>b));i+=(1-2*(a>b)))
#define repa(x, a) for(auto x: a)
#define repr(x, a) for(auto &x: a)
#define prec(n) cout << fixed << setprecision(n)
#define what_is(x) cout << #x << " = " << x << endl

int dr[] = { -1, 0, 1, 0 };
int dc[] = { 0, -1, 0, 1 };

// g++ test.cpp -o test && ./test < input.txt
void solve() {
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(d, 1, 10) {
        for(int i=0; i<n-d; i++) {
            if(d == abs(s[i] - s[i+d])) ans++;
        }
    }
    cout << ans << endl;
}
 
int main() {
    cin.tie(0) -> sync_with_stdio(0);
    int tc = 1; cin >> tc;
    while(tc--) solve();
    return 0;
}

Buddy Look at the starting point of j it goes from I+1 to MIN( I+9, N )

How can It will be N*N. when we are going to at most i+9 for every i.

My solution, It might be helpful
https://www.codechef.com/viewsolution/52332188