제출 #1162109

#제출 시각아이디문제언어결과실행 시간메모리
1162109CrabCNHAirplane (NOI23_airplane)C++20
0 / 100
39 ms12104 KiB
#include <bits/stdc++.h>

#define task   "BriantheCrab"

#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())

using namespace std;

template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}

const int maxN = 2e5 + 5;
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;

int n, m;
int a[maxN];
vector <int> adj[maxN];

namespace sub1 {
    int checker = 0;
    
    void sol () {
        int mx = 0, pos = 1;
        for (int i = 1; i <= n; i ++) {
           if (mx <= a[i]) {
               mx = a[i];
               pos = i;
           }
        }
        int curH = 0, time = 0;
        for (int i = 1; i <= pos; i ++) {
            if (curH == mx) {
                time ++;
            }
            else {
                time += max (a[i] - curH, 1);
                curH = max (curH + 1, a[i]);
            }
        }
        curH = 0;
        for (int i = n - 1; i >= pos; i --) {
            if (curH == mx) {
                time ++;
            }
            else {
                time += max (a[i] - curH, 1);
                curH = max (curH + 1, a[i]);
            }
        }
        cout << time;
        return;
    }
}

namespace sub2 {
    const int N2 = 2e3 + 5;
    
    struct Edge {
        int node, hi;
    };
    
    int L[N2][N2];
    int limH = 0;
    
    int cost (int h1, int h2) {
        if (abs (h1 - h2) <= 1) {
            return 0;
        }
        return abs (h1 - h2) - 1;
    }
    
    void bfs () {
        for (int i = 0; i <= n; i ++) {
            for (int j = 0; j <= limH; j ++) {
                L[i][j] = inf;
            }
        }
        queue <Edge> q;
        L[1][0]= 0;
        q.push ({1, 0});
        while (!q.empty ()) {
            auto [u, h] = q.front ();
            q.pop ();
            cout << u << ' ' << h << '\n';
            for (auto v : adj[u]) {
                for (int nh = a[v]; nh <= limH; nh ++) {
                    if (L[v][nh] == inf) {
                        L[v][nh] = L[u][h] + 1 + cost (nh, h);
                        q.push ({v, nh});
                    }
                }
            }
        }
    }
    
    void sol () {
        limH = *max_element (a + 1, a + n + 1);
        bfs ();
        int res = 0;
        for (int i = 0; i <= limH; i ++) {
            maxi (res, L[n][i] - i);
        }
        cout << res;
    }
}

void solve () {
    cin >> n >> m;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
    }
    for (int i = 1; i <= m; i ++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back (v);
        adj[v].push_back (u);
        if (u == i && v == i + 1) {
            sub1 :: checker ++;
        }
    }
    if (sub1 :: checker == n - 1) {
        sub1 :: sol ();
    }
    else if (n <= 2000 && *max_element (a + 1, a + n + 1) <= 2000) {
        sub2 :: sol ();
    }
    
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t --) {
        solve ();
    } 
    return 0;
}
// thfdgb

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

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