답안 #320834

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
320834 2020-11-10T04:57:52 Z ishi_10 Labels (NOI20_labels) C++14
0 / 100
50 ms 7780 KB
#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,pos,maxx=0;
    for(i=0;i<n-1;i++)
    {
        s=s+a[i];
        if(s>maxx)
        {
            maxx=s;
            pos=i;
        }
    }
    ll ans[n+1];
    ll c=0;
    ans[pos+1]=n;
    ll j,minn=3*(1e5);
    ll posj;
    for(j=pos;j>=0;j--)
    {
        ans[j]=ans[j+1]-a[j];
        if(ans[j]<minn)
        {
            minn=ans[j];
            posj=j;
        }
        if(ans[j]>n || ans[j]<1)
        {
            c=1;
            break;
        }
    }
    for(j=pos+2;j<n;j++)
    {
        ans[j]=ans[j-1]+a[j-1];
        if(ans[j]<minn)
        {
            minn=ans[j];
            posj=j;
        }
        if(ans[j]>n || ans[j]<1)
        {
            c=1;
            break;
        }
    }
    if(c==0)
    {
        if(ans[posj]==1){
            for(i=0;i<n;i++)
                cout<<ans[i]<<" ";
            cout<<"\n";
        }
        else
            cout<<"-1\n";
    }
    else
        cout<<"-1\n";
    cerr<<"\nTime elapsed:"<< 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

Compilation message

Labels.cpp: In function 'int main()':
Labels.cpp:17:12: warning: unused variable 'f' [-Wunused-variable]
   17 |     ll s=0,f=0,pos,maxx=0;
      |            ^
Labels.cpp:62:20: warning: 'posj' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |         if(ans[posj]==1){
      |            ~~~~~~~~^
Labels.cpp:46:10: warning: 'pos' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |     for(j=pos+2;j<n;j++)
      |         ~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 7780 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 24 ms 5860 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -