제출 #1288357

#제출 시각아이디문제언어결과실행 시간메모리
1288357quangminh412Labels (NOI20_labels)C++17
100 / 100
34 ms8052 KiB
/*
  Ben Watson

  Quang Minh MasterDDDDD
*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long

const string name = "test";

void solve();
signed main()
{
    if (fopen((name + ".inp").c_str(), "r"))
    {
        freopen((name + ".inp").c_str(), "r", stdin);
        freopen((name + ".out").c_str(), "w", stdout);
    }
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    solve();

    return 0;
}

// main program
const ll oo = 0x3f3f3f3f3f3f3f3f;

void solve()
{
    int n; cin >> n;
    int d[n];
    ll mn = oo;
    vector<ll> prefix(n, 0);
    for (int i = 1; i < n; i++)
    {
        cin >> d[i];
        prefix[i] = prefix[i - 1] + d[i];
        mn = min(mn, prefix[i]);
    }

    ll fi = max(1ll, 1 - mn);
    vector<ll> res(n + 1, 0);
    res[1] = fi;
    for (int i = 2; i <= n; i++)
        res[i] = prefix[i - 1] + fi;

    bool only_one = false;
    for (int i = 1; i <= n; i++)
    {
        if (!(1 <= res[i] && res[i] <= n))
        {
            cout << -1 << '\n';
            return;
        }
        if (!(1 <= res[i] + 1 && res[i] + 1 <= n))
            only_one = true;
    }
    if (!only_one)
    {
        cout << -1 << '\n';
        return;
    }
    for (int i = 1; i <= n; i++)
        cout << res[i] << ' ';
    cout << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

Labels.cpp: In function 'int main()':
Labels.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen((name + ".inp").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Labels.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...