답안 #1102355

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1102355 2024-10-18T03:05:44 Z LTTrungCHL Airplane (NOI23_airplane) C++17
41 / 100
403 ms 16712 KB
///***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 sub2{
    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];
            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];
            ans = min(ans, res);
        }
        cout << ans;
    }
};
namespace sub1{
    long long dis[N], dis2[N];
    void solve(){
        int mx = 1;
        for (int i = 2;i <= n;++i){
            if (a[mx] < a[i]){
                mx = i;
            }
        }
        for (int i = 2;i <= n;++i){
            int nxt = (dis[i - 1] < a[i] ? a[i] : dis[i - 1] + 1);
            dis[i] = nxt;
        }
        for (int i = n - 1;i >= 1;--i){
            int nxt = (dis2[i - 1] < a[i] ? a[i] : dis2[i - 1] + 1);
            dis2[i] = nxt;
        }
        long long ans = oo * oo;
        ans = min(ans, dis[mx] + dis2[mx]);
        cout << ans;
        return;
    }
};
void solve(){
    cin >> n >> m;
    for (int i = 1;i <= n;++i){
        cin >> a[i];
    }
    bool cksub1 = true;
    for (int i = 1;i <= m;++i){
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
        adj[v].pb(u);
        if (v != u + 1){
            cksub1 = false;
        }
    }
    if (m == n - 1 and cksub1){
        sub1::solve();
        return;
    }
    if (n <= 2000 and m <= 4000){
        sub2::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

Main.cpp: In function 'int main()':
Main.cpp:126:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  126 |         freopen("ltt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:127:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  127 |         freopen("ltt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7504 KB Output is correct
2 Incorrect 46 ms 16712 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7504 KB Output is correct
2 Correct 2 ms 7504 KB Output is correct
3 Correct 2 ms 7520 KB Output is correct
4 Correct 2 ms 7504 KB Output is correct
5 Correct 2 ms 7504 KB Output is correct
6 Correct 12 ms 7708 KB Output is correct
7 Correct 80 ms 7504 KB Output is correct
8 Correct 32 ms 7504 KB Output is correct
9 Correct 194 ms 7504 KB Output is correct
10 Correct 47 ms 7676 KB Output is correct
11 Correct 210 ms 7504 KB Output is correct
12 Correct 73 ms 7504 KB Output is correct
13 Correct 245 ms 7504 KB Output is correct
14 Correct 315 ms 7504 KB Output is correct
15 Correct 403 ms 7504 KB Output is correct
16 Correct 391 ms 7760 KB Output is correct
17 Correct 376 ms 8016 KB Output is correct
18 Correct 2 ms 7504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7504 KB Output is correct
2 Correct 2 ms 7504 KB Output is correct
3 Correct 2 ms 7520 KB Output is correct
4 Correct 2 ms 7504 KB Output is correct
5 Correct 2 ms 7504 KB Output is correct
6 Correct 12 ms 7708 KB Output is correct
7 Correct 80 ms 7504 KB Output is correct
8 Correct 32 ms 7504 KB Output is correct
9 Correct 194 ms 7504 KB Output is correct
10 Correct 47 ms 7676 KB Output is correct
11 Correct 210 ms 7504 KB Output is correct
12 Correct 73 ms 7504 KB Output is correct
13 Correct 245 ms 7504 KB Output is correct
14 Correct 315 ms 7504 KB Output is correct
15 Correct 403 ms 7504 KB Output is correct
16 Correct 391 ms 7760 KB Output is correct
17 Correct 376 ms 8016 KB Output is correct
18 Correct 2 ms 7504 KB Output is correct
19 Correct 60 ms 7504 KB Output is correct
20 Correct 22 ms 7504 KB Output is correct
21 Correct 74 ms 7504 KB Output is correct
22 Correct 138 ms 7504 KB Output is correct
23 Correct 26 ms 7504 KB Output is correct
24 Correct 96 ms 7504 KB Output is correct
25 Correct 176 ms 7504 KB Output is correct
26 Correct 267 ms 7504 KB Output is correct
27 Correct 312 ms 7504 KB Output is correct
28 Correct 247 ms 7760 KB Output is correct
29 Correct 347 ms 7760 KB Output is correct
30 Correct 336 ms 7760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7504 KB Output is correct
2 Incorrect 46 ms 16712 KB Output isn't correct
3 Halted 0 ms 0 KB -