답안 #993696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
993696 2024-06-06T10:12:38 Z amine_aroua Stranded Far From Home (BOI22_island) C++17
35 / 100
1000 ms 31740 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define int long long
#define pb push_back
#define fore(i , n) for(int i = 0 ; i<n;i++)
#define forr(i , x , y) for(int i = x ; i <= y; i++)
#define forn(i , x , y) for(int i = x ; i >= y; i--)
const int N = 2e5 + 10;
vector<int> adj[N];
int a[N];
int n , m;
vector<bool> vis(N , 0);
vector<int> ans(N , -1);
priority_queue<pair<int ,int> , vector<pair<int ,int>>  , greater<pair<int , int>>> pq;
vector<int> possible;
vector<int> nodes;
void expand(int x)
{
    pq = priority_queue<pair<int ,int> , vector<pair<int ,int>>  , greater<pair<int , int>>>();
    int cur = a[x];
    pq.push({cur , x});
    possible.clear();
    nodes.clear();

    while(!pq.empty())
    {
        auto [val , node] = pq.top();
        pq.pop();
        if(val == cur)
        {
            possible.pb(node);
            if(ans[node] == 0)
            {
                for(auto v : nodes)
                    vis[v] = 0;
                ans[x] = 0;
                return ;
            }
        }
        if(val > cur)
            break;
        if(vis[node])
            continue;
        vis[node] = 1;
        nodes.pb(node);
        if(node != x)
            cur+=val;
        if(ans[node] == 1)
        {
            ans[x] = 1;
            for(auto v : nodes)
                vis[v] = 0;
            return;
        }
        for(auto u : adj[node])
        {
            pq.push({a[u] , u});
        }
    }
    bool acc = 1;
    if((int)nodes.size() != n)
        acc = 0;
    for(auto u : nodes)
        vis[u] = 0;
    if(acc)
    {
        ans[x] = 1;
        for(auto u : possible)
            ans[u] = 1;
        for(auto u : nodes)
        {
            if(a[u] != a[x])
                break;
            ans[u] = 1;
        }
    }
    else
    {
        for(auto p : nodes)
        {
            ans[p] = 0;
        }
        ans[x] = 0;
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    n = 2e5 , m = n - 1;
    cin>>n>>m;
    vector<pair<int ,int>> ve;
//    int f[10] = {1 , 2 , 5 , 10 , 20 , 6 , 7 , 18 , 40 , 31};
    fore(i , n)
    {

//        a[i] = f[rand()%10];
        cin>>a[i];
        ve.pb({a[i] , i});
    }
    sort(ve.begin() , ve.end());
    fore(i , m)
    {
        int u , v;
//        u = i + 2 ;
//        v = i + 1;
        cin>>u>>v;
        u-- , v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }
//    int cnt = 0;
    for(auto [val , i] : ve)
    {
        if(ans[i] == -1)
        {
            expand(i);
        }
    }
    fore(i , n)
    {
        cout<<ans[i];
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 3 ms 6744 KB Output is correct
4 Correct 4 ms 6748 KB Output is correct
5 Correct 6 ms 6904 KB Output is correct
6 Correct 5 ms 6748 KB Output is correct
7 Correct 5 ms 6748 KB Output is correct
8 Correct 4 ms 6744 KB Output is correct
9 Correct 5 ms 7004 KB Output is correct
10 Correct 5 ms 6748 KB Output is correct
11 Correct 6 ms 6748 KB Output is correct
12 Correct 7 ms 6776 KB Output is correct
13 Correct 5 ms 6744 KB Output is correct
14 Correct 12 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Correct 4 ms 6744 KB Output is correct
3 Correct 147 ms 26804 KB Output is correct
4 Correct 110 ms 25560 KB Output is correct
5 Correct 468 ms 26244 KB Output is correct
6 Correct 497 ms 26924 KB Output is correct
7 Correct 455 ms 26728 KB Output is correct
8 Correct 148 ms 28096 KB Output is correct
9 Correct 214 ms 28096 KB Output is correct
10 Correct 155 ms 31740 KB Output is correct
11 Correct 157 ms 29240 KB Output is correct
12 Correct 160 ms 25540 KB Output is correct
13 Correct 96 ms 24260 KB Output is correct
14 Correct 94 ms 24448 KB Output is correct
15 Correct 105 ms 25796 KB Output is correct
16 Correct 82 ms 25004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 281 ms 25796 KB Output is correct
3 Correct 285 ms 25792 KB Output is correct
4 Correct 158 ms 30664 KB Output is correct
5 Correct 108 ms 28516 KB Output is correct
6 Correct 298 ms 25764 KB Output is correct
7 Correct 117 ms 25748 KB Output is correct
8 Correct 119 ms 25776 KB Output is correct
9 Correct 81 ms 24968 KB Output is correct
10 Correct 121 ms 25284 KB Output is correct
11 Correct 162 ms 24360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Correct 436 ms 26888 KB Output is correct
3 Correct 672 ms 26820 KB Output is correct
4 Correct 583 ms 26824 KB Output is correct
5 Correct 512 ms 26764 KB Output is correct
6 Correct 118 ms 26560 KB Output is correct
7 Correct 142 ms 30300 KB Output is correct
8 Execution timed out 1074 ms 28640 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 6744 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 3 ms 6744 KB Output is correct
4 Correct 4 ms 6748 KB Output is correct
5 Correct 6 ms 6904 KB Output is correct
6 Correct 5 ms 6748 KB Output is correct
7 Correct 5 ms 6748 KB Output is correct
8 Correct 4 ms 6744 KB Output is correct
9 Correct 5 ms 7004 KB Output is correct
10 Correct 5 ms 6748 KB Output is correct
11 Correct 6 ms 6748 KB Output is correct
12 Correct 7 ms 6776 KB Output is correct
13 Correct 5 ms 6744 KB Output is correct
14 Correct 12 ms 6748 KB Output is correct
15 Correct 3 ms 6748 KB Output is correct
16 Correct 4 ms 6744 KB Output is correct
17 Correct 147 ms 26804 KB Output is correct
18 Correct 110 ms 25560 KB Output is correct
19 Correct 468 ms 26244 KB Output is correct
20 Correct 497 ms 26924 KB Output is correct
21 Correct 455 ms 26728 KB Output is correct
22 Correct 148 ms 28096 KB Output is correct
23 Correct 214 ms 28096 KB Output is correct
24 Correct 155 ms 31740 KB Output is correct
25 Correct 157 ms 29240 KB Output is correct
26 Correct 160 ms 25540 KB Output is correct
27 Correct 96 ms 24260 KB Output is correct
28 Correct 94 ms 24448 KB Output is correct
29 Correct 105 ms 25796 KB Output is correct
30 Correct 82 ms 25004 KB Output is correct
31 Correct 3 ms 6744 KB Output is correct
32 Correct 281 ms 25796 KB Output is correct
33 Correct 285 ms 25792 KB Output is correct
34 Correct 158 ms 30664 KB Output is correct
35 Correct 108 ms 28516 KB Output is correct
36 Correct 298 ms 25764 KB Output is correct
37 Correct 117 ms 25748 KB Output is correct
38 Correct 119 ms 25776 KB Output is correct
39 Correct 81 ms 24968 KB Output is correct
40 Correct 121 ms 25284 KB Output is correct
41 Correct 162 ms 24360 KB Output is correct
42 Correct 3 ms 6748 KB Output is correct
43 Correct 436 ms 26888 KB Output is correct
44 Correct 672 ms 26820 KB Output is correct
45 Correct 583 ms 26824 KB Output is correct
46 Correct 512 ms 26764 KB Output is correct
47 Correct 118 ms 26560 KB Output is correct
48 Correct 142 ms 30300 KB Output is correct
49 Execution timed out 1074 ms 28640 KB Time limit exceeded
50 Halted 0 ms 0 KB -