Plzz Help me i have written a solution but its failing on a single test case..

Правка en1, от livingonhope, 2025-09-20 16:13:36

Heres the code and problem link as well plzz help me undertand why is it failing .it will be very helpfull Problem Link — https://mirror.codeforces.com/contest/1829/problem/G Code ( C++) :

include <bits/stdc++.h>

using namespace std;

define ll long long

set ans;

int compute_row(int x) { int l = 1, r = 50000; while (l < r) { int m = (l + r) / 2; if (m * (m + 1) / 2 >= x) r = m; else l = m + 1; } return l; }

vector dp;

void solve(int n) { if (n <= 0 || dp[n]) return; dp[n] = 1;

ans.insert(n);

int row = compute_row(n);
int val1 = n - row;
int val2 = n - row + 1;

if (val1 >= 1 && compute_row(val1) < row)
    solve(val1);

if (val2 >= 1 && compute_row(val2) < row)
    solve(val2);

}

int main() { int t; cin >> t; while (t--) { int n; cin >> n; ans.clear(); dp.assign(n + 10, 0);

solve(n);

    ll sum = 0;
    for (int x : ans) sum += 1LL * x * x;

    cout << sum << endl;
}

}

Теги unsolved, dp, codeforces, c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский livingonhope 2025-09-20 16:13:36 1195 Initial revision (published)