Submission #1102343

#TimeUsernameProblemLanguageResultExecution timeMemory
1102343LTTrungCHLAirplane (NOI23_airplane)C++17
41 / 100
401 ms13452 KiB
///***LTT***/// /// ->NHAT QUOC GIA<- /// #include<bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") //#define int long long #define endl "\n" #define F first #define S second #define pb push_back using namespace std; vector <int> lg2; //void MAKE_LOG_ARR(int n){ // lg2.resize(n + 3); // for (int i = 1;i <= n;++i){ // lg2[i] = __lg(i); // } //} const long long oo = 1e9+7; const int N = 2 * 1e5 + 10; int n, a[N], m; vector <int> adj[N]; namespace sub{ long long dis[N]; priority_queue <pair <long long, int>> pq; void solve(){ long long ans = oo * oo; for (int i = 1;i <= n;++i){ for (int j = 1;j <= n;++j){ dis[j] = oo * oo; } dis[1] = 0; pq.push({0,1}); while (!pq.empty()){ int u = pq.top().S; long long d = -pq.top().F; pq.pop(); for (int v : adj[u]){ if (a[v] > a[i]) continue; int nxt = (d < a[v] ? a[v] : d + 1); if (nxt < dis[v]){ dis[v] = nxt; pq.push({-dis[v], v}); } } } long long res = dis[i]; // cout << i <<" "<< res <<"\n"; for (int j = 1;j <= n;++j){ dis[j] = oo * oo; } dis[n] = 0; pq.push({0,n}); while (!pq.empty()){ int u = pq.top().S; long long d = -pq.top().F; pq.pop(); for (int v : adj[u]){ if (a[v] > a[i]) continue; int nxt = (d < a[v] ? a[v] : d + 1); if (nxt < dis[v]){ dis[v] = nxt; pq.push({-dis[v], v}); } } } res += dis[i]; // cout << i <<" "<< res <<" "<< dis[9] <<"\n"; ans = min(ans, res); } cout << ans; } }; 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].pb(v); adj[v].pb(u); } if (n <= 2000 and m <= 4000){ sub::solve(); return; } return; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); if (fopen("ltt.inp", "r")){ freopen("ltt.inp", "r", stdin); freopen("ltt.out", "w", stdout); } // int t; // cin >> t; // while(t--){ solve(); // } return 0; }

Compilation message (stderr)

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