#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int ll;
const ll maxn=1e5+2;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n;
cin>>n;
ll a[n-1],i;
for(i=0;i<n-1;i++)
cin>>a[i];
ll s=0,f=0;
for(i=0;i<n-1;i++)
{
s=s+a[i];
if(s==n-1)
{
f=1;
break;
}
if(s==1-n)
{
f=2;
break;
}
if(s>=n || s<=((-1)*n))
{
f=0;
break;
}
}
if(f==0)
cout<<"-1"<<"\n";
else
{
if(f==1)
{
ll c=0;
ll ans[n+1];
ans[i+1]=n;
ll j;
for(j=i;j>=0;j--)
{
ans[j]=ans[j+1]-a[j];
if(ans[j]>n || ans[j]<1)
{
c=1;
break;
}
}
for(j=i+2;j<n;j++)
{
ans[j]=ans[j-1]+a[j-1];
if(ans[j]>n || ans[j]<1)
{
c=1;
break;
}
}
if(c==0)
{
for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<"\n";
}
else
cout<<"-1\n";
}
else
{
ll c=0;
ll ans[n+1];
ans[i+1]=1;
ll j;
for(j=i;j>=0;j--)
{
ans[j]=ans[j+1]-a[j];
if(ans[j]>n || ans[j]<1)
{
c=1;
break;
}
}
for(j=i+2;j<n;j++)
{
ans[j]=ans[j-1]+a[j-1];
if(ans[j]>n || ans[j]<1)
{
c=1;
break;
}
}
if(c==0)
{
for(i=0;i<n;i++)
cout<<ans[i]<<" ";
cout<<"\n";
}
else
cout<<"-1\n";
}
}
cerr<<"\nTime elapsed:"<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
7012 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
52 ms |
7520 KB |
Output is correct |
4 |
Correct |
24 ms |
3180 KB |
Output is correct |
5 |
Correct |
23 ms |
3180 KB |
Output is correct |
6 |
Correct |
23 ms |
3172 KB |
Output is correct |
7 |
Correct |
21 ms |
3172 KB |
Output is correct |
8 |
Correct |
25 ms |
3180 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |