Submission #993677

# Submission time Handle Problem Language Result Execution time Memory
993677 2024-06-06T10:04:00 Z amine_aroua Stranded Far From Home (BOI22_island) C++17
35 / 100
1000 ms 28804 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;
    }
    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 + 1 ;
//        v = i + 2;
        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];
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Correct 2 ms 6576 KB Output is correct
3 Correct 3 ms 6744 KB Output is correct
4 Correct 5 ms 6744 KB Output is correct
5 Correct 4 ms 6748 KB Output is correct
6 Correct 5 ms 6744 KB Output is correct
7 Correct 4 ms 6808 KB Output is correct
8 Correct 5 ms 6744 KB Output is correct
9 Correct 4 ms 6748 KB Output is correct
10 Correct 4 ms 6748 KB Output is correct
11 Correct 4 ms 6748 KB Output is correct
12 Correct 5 ms 6748 KB Output is correct
13 Correct 4 ms 6828 KB Output is correct
14 Correct 12 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 3 ms 6748 KB Output is correct
3 Correct 151 ms 22416 KB Output is correct
4 Correct 129 ms 22472 KB Output is correct
5 Correct 483 ms 22024 KB Output is correct
6 Correct 498 ms 22448 KB Output is correct
7 Correct 512 ms 22396 KB Output is correct
8 Correct 168 ms 23812 KB Output is correct
9 Correct 300 ms 23748 KB Output is correct
10 Correct 171 ms 28156 KB Output is correct
11 Correct 167 ms 25916 KB Output is correct
12 Correct 206 ms 22344 KB Output is correct
13 Correct 118 ms 21440 KB Output is correct
14 Correct 112 ms 21444 KB Output is correct
15 Correct 116 ms 21356 KB Output is correct
16 Correct 104 ms 21188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6748 KB Output is correct
2 Correct 370 ms 22732 KB Output is correct
3 Correct 374 ms 24072 KB Output is correct
4 Correct 228 ms 28804 KB Output is correct
5 Correct 124 ms 27324 KB Output is correct
6 Correct 379 ms 24000 KB Output is correct
7 Correct 128 ms 24008 KB Output is correct
8 Correct 132 ms 23960 KB Output is correct
9 Correct 87 ms 23320 KB Output is correct
10 Correct 174 ms 23488 KB Output is correct
11 Correct 203 ms 23268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6744 KB Output is correct
2 Correct 494 ms 25004 KB Output is correct
3 Correct 864 ms 24848 KB Output is correct
4 Correct 595 ms 24964 KB Output is correct
5 Correct 589 ms 24872 KB Output is correct
6 Correct 425 ms 24516 KB Output is correct
7 Correct 154 ms 28476 KB Output is correct
8 Execution timed out 1053 ms 27220 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6748 KB Output is correct
2 Correct 2 ms 6576 KB Output is correct
3 Correct 3 ms 6744 KB Output is correct
4 Correct 5 ms 6744 KB Output is correct
5 Correct 4 ms 6748 KB Output is correct
6 Correct 5 ms 6744 KB Output is correct
7 Correct 4 ms 6808 KB Output is correct
8 Correct 5 ms 6744 KB Output is correct
9 Correct 4 ms 6748 KB Output is correct
10 Correct 4 ms 6748 KB Output is correct
11 Correct 4 ms 6748 KB Output is correct
12 Correct 5 ms 6748 KB Output is correct
13 Correct 4 ms 6828 KB Output is correct
14 Correct 12 ms 6748 KB Output is correct
15 Correct 2 ms 6748 KB Output is correct
16 Correct 3 ms 6748 KB Output is correct
17 Correct 151 ms 22416 KB Output is correct
18 Correct 129 ms 22472 KB Output is correct
19 Correct 483 ms 22024 KB Output is correct
20 Correct 498 ms 22448 KB Output is correct
21 Correct 512 ms 22396 KB Output is correct
22 Correct 168 ms 23812 KB Output is correct
23 Correct 300 ms 23748 KB Output is correct
24 Correct 171 ms 28156 KB Output is correct
25 Correct 167 ms 25916 KB Output is correct
26 Correct 206 ms 22344 KB Output is correct
27 Correct 118 ms 21440 KB Output is correct
28 Correct 112 ms 21444 KB Output is correct
29 Correct 116 ms 21356 KB Output is correct
30 Correct 104 ms 21188 KB Output is correct
31 Correct 2 ms 6748 KB Output is correct
32 Correct 370 ms 22732 KB Output is correct
33 Correct 374 ms 24072 KB Output is correct
34 Correct 228 ms 28804 KB Output is correct
35 Correct 124 ms 27324 KB Output is correct
36 Correct 379 ms 24000 KB Output is correct
37 Correct 128 ms 24008 KB Output is correct
38 Correct 132 ms 23960 KB Output is correct
39 Correct 87 ms 23320 KB Output is correct
40 Correct 174 ms 23488 KB Output is correct
41 Correct 203 ms 23268 KB Output is correct
42 Correct 2 ms 6744 KB Output is correct
43 Correct 494 ms 25004 KB Output is correct
44 Correct 864 ms 24848 KB Output is correct
45 Correct 595 ms 24964 KB Output is correct
46 Correct 589 ms 24872 KB Output is correct
47 Correct 425 ms 24516 KB Output is correct
48 Correct 154 ms 28476 KB Output is correct
49 Execution timed out 1053 ms 27220 KB Time limit exceeded
50 Halted 0 ms 0 KB -