Submission #1162071

#TimeUsernameProblemLanguageResultExecution timeMemory
1162071CrabCNHAirplane (NOI23_airplane)C++20
0 / 100
5 ms3396 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 = 1e5 + 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 < a[i]) { time += ((a[i] - curH) - 1); curH = a[i]; } else { time ++; } } time += (n - (pos + 1) - 1); curH -= (n - (pos + 1) - 1); cout << time + curH; 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

Compilation message (stderr)

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