When I run the code below for the problem farmer drama - AIO 2016 (https://orac.amt.edu.au/cgi-bin/train/problem.pl?set=aio16int&problemid=903),
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("farmin.txt", "r", stdin);
//freopen("farmout.txt", "w", stdout);
int n; cin >> n;
vector<int> p(n);
for (int i=0; i<n; i++) {
cin >> p[i];
}
int f=p[0], l=p[n-1], i1=0, i2=n-1, c=0;
while (i1!=i2) {
if (f==l) {
--i2; ++i1;
f = p[i1]; l = p[i2];
continue;
}
if (f<l) {
++i1;
f = f+p[i1];
c++;
}
if (l<f) {
--i2;
l = l+p[i2];
c++;
}
}
cout << c << '\n';
return 0;
}
the terminal returns shell returned -1073741819 even though the logic is perfectly fine. The exact error message is below:
C:\WINDOWS\system32\cmd.exe /c (AIO\2016\farmer)
6
1 1 1 1 1 1
shell returned -1073741819
Hit any key to close this window...
While if I run a different input such as:
8
1 2 2 5 1 3 1 1
it runs perfectly fine and returns the correct output: 3.
This has been happening quite frequently but I don't know what is causing it. Could you please help me as this is quite frustrating?
Aucun commentaire:
Enregistrer un commentaire