ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1044. Lucky Tickets. Easy!

WA test 3. But it answers correctly on my machine...
Posted by jedianmb 31 Jan 2020 16:03
Can't find the error, because it gives the same answers as those stupid precalc solutions:

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int soma[40] = {0};

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, i, lim;
  ll ans = 0;
  cin >> n;
  lim = pow(10, n/2);
  for(i=0; i<lim; ++i){
      soma[i%10 + (i/10)%10 + (i/100)%10 + (i/1000)%10]++;
  }
  for(i=0; i<=n*9; ++i){
      ans += soma[i]*soma[i];
  }
  cout << ans << '\n';
  return 0;
}
Re: WA test 3. But it answers correctly on my machine...
Posted by ToadMonster 31 Jan 2020 17:11
  for(i=0; i<=n*9; ++i){
      ans += soma[i]*soma[i];
  }

i is out of soma range.