AshToady's blog

By AshToady, history, 3 years ago, In English

here's my code to the most annoying problem i've ever encountered(its a recent one, so you probably know it),

i'm getting 2147483647 runtime error.

Having submitted over 15/20 codes over a period of a week, and researching on it, i'm sure my algorithm is correct, have checked it innumerable times.

To simplify the logic-> its grouping numbers with matching largest bits and feeding it to calc function for further recursion till required.

what is this error 2147483647? i've faced it many times, but never really understood it, it always magically somehow gets resolved, except this time.

need help!

and if you can spot the mistake, kindly let me know.

Full text and comments »

  • Vote: I like it
  • -20
  • Vote: I do not like it

By AshToady, history, 3 years ago, In English

Considering everything i could find on maps, unordered maps are supposed to be faster than maps. I experimented on a cses problem, and surprisingly unordered map gave TLE on a few test cases whereas map passed them all.

problem

Code

#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;
#define int long long
 main()
{
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
int n,x;cin>>n>>x;int a[n+1];

 for(int i=1;i<=n;cin>>a[i++]);
  a[0]=0;
  unordered_map<int,int>mp;
  for(int i=1;i<=n;i++)
  {
    a[i]+=a[i-1];mp[a[i]]++;
  }
  mp[0]++;
  int cnt=0;

  for(int i=n;i>0;i--)
  {  mp[a[i]]--;
      cnt+=mp[a[i]-x];

    //cnt+=k;
    //cout<<it1-a<<it-a<<endl;
  }
cout<<cnt;
}

Full text and comments »

  • Vote: I like it
  • -1
  • Vote: I do not like it

By AshToady, history, 3 years ago, In English

solution with settings=c++14 solution with settings=c++17 I have never used gnu c++17 as my setting, always c++14. But what actually happened was, in my ide, visual studio, test case-2 gave correct output=13...but on codeforces results of the test was showing output=11 wrong ans. i thought this is some codeforces glitch, i changed the code variables a bit to be able to submit the same code again. But nothing changed. Then i randomly thought of changing lang to c++ 17...and it gave all correct outputs->accepted i.e.

I dont what i should do...its been an year, never used c++17 settings... why did this happen today?

Full text and comments »

  • Vote: I like it
  • -15
  • Vote: I do not like it