Submission #573237

# Submission time Handle Problem Language Result Execution time Memory
573237 2022-06-06T09:44:22 Z AmirElarbi Stranded Far From Home (BOI22_island) C++14
10 / 100
1000 ms 32060 KB
#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9+7
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 2e5+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
vii s;
vi adj[nax];
ll mn = INF,res = 0, vl[nax];
ll ans[nax];
bool vis[nax], cur[nax];
vi cdfs;
void dfs(int u){
    cdfs.pb(u);
    cur[u] = 1;
    res += vl[u];
    for(auto x : adj[u]){
        if(vis[x]){
            if(ans[x] == 1) mn = min(mn,vl[x]);
            continue;
        }
        if(cur[x]) continue;
        dfs(x);
    }
}
int main(){
    optimise;
    int n,m;
    cin >>n >> m;
    for (int i = 0; i < n; ++i)
    {
        int val;
        cin >> val;
        vl[i] = val;
        s.pb({val,i});
    }
    for (int i = 0; i < m; ++i)
    {
        int a,b;
        cin >> a >> b;
        a--,b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    sort(s.begin(), s.end(), greater<ii>());
    vis[s[0].se] = 1;
    ans[s[0].se] = 1;
    for (int i = 1; i < n; ++i)
    {
        mn = INF,res = 0;
        dfs(s[i].se);
        if(res >= mn) ans[s[i].se] = 1;
        vis[s[i].se] = 1;
        for(auto x: cdfs)
            cur[x] = 0;
        cdfs.clear();
    }
    for (int i = 0; i < n; ++i)
    {
        cout << ans[i];
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 24 ms 5192 KB Output is correct
5 Correct 7 ms 5076 KB Output is correct
6 Correct 23 ms 5184 KB Output is correct
7 Correct 23 ms 5272 KB Output is correct
8 Correct 20 ms 5180 KB Output is correct
9 Correct 32 ms 5204 KB Output is correct
10 Correct 4 ms 5204 KB Output is correct
11 Correct 6 ms 5128 KB Output is correct
12 Correct 6 ms 5144 KB Output is correct
13 Correct 48 ms 5280 KB Output is correct
14 Correct 8 ms 5156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Execution timed out 1090 ms 22596 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 558 ms 24612 KB Output is correct
3 Correct 502 ms 26180 KB Output is correct
4 Execution timed out 1091 ms 32060 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Execution timed out 1083 ms 17600 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 4 ms 4948 KB Output is correct
3 Correct 4 ms 4948 KB Output is correct
4 Correct 24 ms 5192 KB Output is correct
5 Correct 7 ms 5076 KB Output is correct
6 Correct 23 ms 5184 KB Output is correct
7 Correct 23 ms 5272 KB Output is correct
8 Correct 20 ms 5180 KB Output is correct
9 Correct 32 ms 5204 KB Output is correct
10 Correct 4 ms 5204 KB Output is correct
11 Correct 6 ms 5128 KB Output is correct
12 Correct 6 ms 5144 KB Output is correct
13 Correct 48 ms 5280 KB Output is correct
14 Correct 8 ms 5156 KB Output is correct
15 Correct 3 ms 4948 KB Output is correct
16 Correct 3 ms 4948 KB Output is correct
17 Execution timed out 1090 ms 22596 KB Time limit exceeded
18 Halted 0 ms 0 KB -