제출 #1339490

#제출 시각아이디문제언어결과실행 시간메모리
1339490tuanhung0Airplane (NOI23_airplane)C++20
22 / 100
37 ms1984 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb emplace_back
const int mod = 1e9 + 7;
const int nmax = 2e5 + 5;
int n, m, a[nmax], suf[nmax];

void sub1() {
    for (int i = n; i >= 1; --i) suf[i] = max(suf[i + 1], a[i]);
    int cur = 0, ans = 0;
    for (int i = 1; i < n; ++i) {
        while (cur < a[i + 1] - 1) {
            ++cur;
            ++ans;
        }

        if (cur < suf[i + 1]) ++cur;
        else if (cur > suf[i + 1]) --cur;
        ++ans;
    }

    cout << ans + cur;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    if (fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }

    cin >> n >> m;
    bool checksub1 = (m == n - 1);
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= m; ++i) {
        int u, v; cin >> u >> v;
        if (u != i || v != i + 1) checksub1 = 0;
    }

    if (checksub1) sub1();

    return 0;
}

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

Main.cpp: In function 'int main()':
Main.cpp:33:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("test.out", "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...