Hi guys, what did that mean " Probably, the solution is executed with error 'uninitialized value usage' on the line 38 " ?
and thank's in advance
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3603 |
| 4 | jiangly | 3583 |
| 5 | turmax | 3559 |
| 6 | tourist | 3541 |
| 7 | strapple | 3515 |
| 8 | ksun48 | 3461 |
| 9 | dXqwq | 3436 |
| 10 | Otomachi_Una | 3413 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 157 |
| 2 | adamant | 153 |
| 3 | Um_nik | 147 |
| 3 | Proof_by_QED | 147 |
| 5 | Dominater069 | 145 |
| 6 | errorgorn | 141 |
| 7 | cry | 139 |
| 8 | YuukiS | 135 |
| 9 | TheScrasse | 134 |
| 10 | chromate00 | 133 |
Hi guys, what did that mean " Probably, the solution is executed with error 'uninitialized value usage' on the line 38 " ?
and thank's in advance
| Name |
|---|



Let's say you've declared an integer
nthat denotes the number of elements to be input. In C/C++, if you don't initialise your variables (manually or through input), they're likely going to contain some junk value, say -431094 or whatever that was present there previously. Now, imagine what happens if you try to declare a vector of size n. Boom. There are various places where this might cause an issue but I'm not going to mention all of the ones I know.In your case, which I found in your submissions,
xxandyyare uninitialized to begin with. So, when you do an equality check, CF tools detect this and flag it as RTE.include <bits/stdc++.h>
using namespace std;
int main() { int n,a[n+1]; // Probably, the solution is executed with error 'uninitialized value usage' on the line scanf("%d", &n);
for(int i=0; i<n; i++) { scanf("%d", &a[i]); } sort(a,a+n); long long moves = 0; for(int i=1; i<=n; i++) { moves += abs(a[i]-i); } printf("%I64d", moves); return 0;}
Why can't I declare a[n+1]. Please reply, thanks in advance!
1) That syntax is not part of C++, it's work only as GCC extension;
2) What do you mean by "can't declare"? You getting some compilation error or what? With extension you can declare array that way;
3) In your code (seriously plz use some formatting in comments — it's horrible to read) problem is you use variable $$$a[n]$$$ which you never read.