Submission #721139

# Submission time Handle Problem Language Result Execution time Memory
721139 2023-04-10T11:19:36 Z YENGOYAN Stranded Far From Home (BOI22_island) C++17
20 / 100
1000 ms 39728 KB
    /*
                                                //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
                                                \\                                    //
                                                //  271828___182845__904523__53602__  \\
                                                \\  87___47____13______52____66__24_  //
                                                //  97___75____72______47____09___36  \\
                                                \\  999595_____74______96____69___67  //
                                                //  62___77____24______07____66__30_  \\
                                                \\  35___35____47______59____45713__  //
                                                //                                    \\
                                                \\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
    */
    #include <iostream>
    #include <vector>
    #include <set>
    #include <map>
    #include <unordered_map>
    #include <unordered_set>
    #include <cmath>
    #include <climits>
    #include <algorithm>
    #include <random>
    #include <queue>
    #include <deque>
    #include <iomanip>
    #include <string>
    #include <tuple>
    #include <bitset>
    #include <chrono>
    #include <ctime>
    #include <fstream>
    #include <stack>
    #include <cstdio>
    #include <functional>
     
    using namespace std;
    using LL = long long;
    const int N = 1e5 + 5;
    const LL mod = 1e9 + 7, inf = 1e18;
     
    vector<int> dx = { 1, 0, 0, -1, 1, 1, -1, -1 };
    vector<int> dy = { 0, 1, -1, 0, 1, -1, 1, -1 };
     
    void solve() {
      int n, m; cin >> n >> m;
      vector<int> s(n);
      map<int, vector<int>> srt;
      for(int i = 0; i < n; ++i){
        cin >> s[i];
        srt[s[i]].push_back(i);
      }
      vector<int> t = s;
      sort(t.begin(), t.end());
      vector<vector<int>> gp(n);
      for(int i = 0; i < m; ++i){
        int u, v; cin >> u >> v;
        gp[--u].push_back(--v);
        gp[v].push_back(u);
      }
      vector<LL> par(n), sz(n);
      for(int i = 0; i < n; ++i){
        par[i] = i;
        sz[i] = s[i];
      }
      string ans(n, '1');
      vector<int> vis(n, -1);
      map<pair<int, int>, int> answ;
      int tm = 0;
      function<int(int, int)> check = [&](int u, int timer){
        if(answ.find(make_pair(timer, u)) != answ.end()) {
          return answ[make_pair(timer, u)];
        }
        if(ans[u] == '0') return 0;
        if(par[u] == u) return 1;
        int r = check(par[u], timer);
        if(!r) ans[u] = '0';
 //       answ[make_pair(timer, u)] = r;
        return r;
      };
      function<LL(LL)> get = [&](LL u){
        if(par[u] == u) return u;
        if(!check(u, tm)) ans[u] = '0';
        return par[u] = get(par[u]);
      };
      function<void(int u, int v)> unions = [&](int u, int v){
        int a = get(u), b = get(v);
        if(a == b) return;
        par[b] = a;
        sz[a] += sz[b];
      };
      for(auto x : srt){
        vector<int> nodes = x.second;
        int cnt = x.first;
        for(int &u : nodes){
          for(int &v : gp[u]){
            if(s[v] <= s[u]){
              ++tm;
              int p = get(v);
              if(sz[p] < cnt){
                ans[p] = '0';
              }
            }
          }
        }
        for(int &u : nodes) {
          for(int &v : gp[u]){
            if(s[v] <= s[u]){
              unions(u, v);
            }
          }
        }
      }
      vis = vector<int> (n, -1);
      for(int i = 0; i < n; ++i){
        get(i);
        cout << ans[i];
      }
      cout << "\n";
    }
     
    int main() {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      // int t; cin >> t; while (t--)
      solve();
     
    }
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 238 ms 39656 KB Output is correct
4 Correct 167 ms 19172 KB Output is correct
5 Correct 231 ms 38328 KB Output is correct
6 Correct 209 ms 34600 KB Output is correct
7 Correct 257 ms 39648 KB Output is correct
8 Correct 214 ms 19376 KB Output is correct
9 Correct 175 ms 34468 KB Output is correct
10 Correct 180 ms 35260 KB Output is correct
11 Correct 115 ms 20064 KB Output is correct
12 Correct 170 ms 19156 KB Output is correct
13 Correct 156 ms 19232 KB Output is correct
14 Correct 143 ms 19032 KB Output is correct
15 Correct 241 ms 39728 KB Output is correct
16 Correct 174 ms 39240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 393 ms 39408 KB Output is correct
3 Correct 338 ms 34532 KB Output is correct
4 Correct 179 ms 19288 KB Output is correct
5 Correct 171 ms 19260 KB Output is correct
6 Correct 369 ms 39584 KB Output is correct
7 Correct 287 ms 39640 KB Output is correct
8 Correct 292 ms 39644 KB Output is correct
9 Correct 204 ms 39252 KB Output is correct
10 Execution timed out 1093 ms 36128 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 317 ms 18736 KB Output is correct
3 Correct 280 ms 18744 KB Output is correct
4 Correct 320 ms 18892 KB Output is correct
5 Correct 284 ms 19308 KB Output is correct
6 Correct 334 ms 18424 KB Output is correct
7 Execution timed out 1081 ms 22412 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 3 ms 724 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 2 ms 596 KB Output is correct
8 Correct 3 ms 540 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 238 ms 39656 KB Output is correct
18 Correct 167 ms 19172 KB Output is correct
19 Correct 231 ms 38328 KB Output is correct
20 Correct 209 ms 34600 KB Output is correct
21 Correct 257 ms 39648 KB Output is correct
22 Correct 214 ms 19376 KB Output is correct
23 Correct 175 ms 34468 KB Output is correct
24 Correct 180 ms 35260 KB Output is correct
25 Correct 115 ms 20064 KB Output is correct
26 Correct 170 ms 19156 KB Output is correct
27 Correct 156 ms 19232 KB Output is correct
28 Correct 143 ms 19032 KB Output is correct
29 Correct 241 ms 39728 KB Output is correct
30 Correct 174 ms 39240 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 393 ms 39408 KB Output is correct
33 Correct 338 ms 34532 KB Output is correct
34 Correct 179 ms 19288 KB Output is correct
35 Correct 171 ms 19260 KB Output is correct
36 Correct 369 ms 39584 KB Output is correct
37 Correct 287 ms 39640 KB Output is correct
38 Correct 292 ms 39644 KB Output is correct
39 Correct 204 ms 39252 KB Output is correct
40 Execution timed out 1093 ms 36128 KB Time limit exceeded
41 Halted 0 ms 0 KB -