Submission #625258

# Submission time Handle Problem Language Result Execution time Memory
625258 2022-08-09T17:37:52 Z Ooops_sorry Stranded Far From Home (BOI22_island) C++14
0 / 100
1000 ms 14416 KB
#include<bits/stdc++.h>

using namespace std;

mt19937 rnd(51);

#define ll long long
#define pb push_back
#define ld long double

const int N = 2e5 + 10;
vector<int> g[N];
vector<bool> used(N);

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> s(n), good(n), bad(n);
    int mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        mx = max(mx, s[i]);
    }
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    vector<int> ord(n);
    iota(ord.begin(), ord.end(), 0);
    sort(ord.begin(), ord.end(), [&](int i, int j){return s[i] > s[j];});
    for (auto i : ord) {
        if (s[i] == mx) {
            good[i] = 1;
            continue;
        }
        ll sum = s[i];
        vector<int> arr{i};
        set<pair<int,int>> st;
        used[i] = 1;
        for (auto to : g[i]) {
             if (!used[to]) {
                used[to] = 1;
                arr.pb(to);
                st.insert({s[to], to});
            }
        }
        while (st.size() > 0 && st.begin()->first <= sum) {
            int v = st.begin()->second;
            sum += st.begin()->first;
            for (auto to : g[v]) {
                if (!used[to]) {
                    used[to] = 1;
                    arr.pb(to);
                    st.insert({s[to], to});
                }
            }
        }
        if (arr.size() == n) good[i] = 1;
        if (!good[i]) {
            for (auto to : arr) {
                bad[to] = 1;
            }
        }
        for (auto to : arr) {
            used[to] = 0;
        }
    }
    for (int i = 0; i < n; i++) {
        cout << good[i];
    }
    cout << endl;
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:66:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         if (arr.size() == n) good[i] = 1;
      |             ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 4948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1077 ms 4948 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Execution timed out 1079 ms 14300 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4948 KB Output is correct
2 Execution timed out 1081 ms 14416 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 4948 KB Time limit exceeded
2 Halted 0 ms 0 KB -