답안 #721048

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721048 2023-04-10T08:58:41 Z YENGOYAN Stranded Far From Home (BOI22_island) C++17
35 / 100
1000 ms 43476 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');
  function<int(int)> get = [&](int u){
    if(par[u] == u) return u;
    return 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];
  };
  vector<int> vis(n, -1);
  function<int(int)> check = [&](int u){
    if(vis[u] != -1) return vis[u];
    if(ans[u] == '0') return vis[u] = 0;
    if(par[u] == u) return vis[u] = 1;
    return vis[u] = check(par[u]);
  };
  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]){
          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);
        }
      }
    }
  }
  for(int i = 0; i < n; ++i){
    cout << check(i);
  }
  cout << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
 // int t; cin >> t; while (t--)
    solve();

}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 4 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 3 ms 596 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 200 ms 38996 KB Output is correct
4 Correct 196 ms 22256 KB Output is correct
5 Correct 211 ms 42004 KB Output is correct
6 Correct 198 ms 38264 KB Output is correct
7 Correct 244 ms 43468 KB Output is correct
8 Correct 190 ms 23908 KB Output is correct
9 Correct 179 ms 38348 KB Output is correct
10 Correct 179 ms 38332 KB Output is correct
11 Correct 114 ms 23392 KB Output is correct
12 Correct 170 ms 22232 KB Output is correct
13 Correct 199 ms 22280 KB Output is correct
14 Correct 149 ms 22136 KB Output is correct
15 Correct 211 ms 43436 KB Output is correct
16 Correct 157 ms 42388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 337 ms 38764 KB Output is correct
3 Correct 320 ms 33940 KB Output is correct
4 Correct 150 ms 19248 KB Output is correct
5 Correct 160 ms 19320 KB Output is correct
6 Correct 361 ms 39004 KB Output is correct
7 Correct 224 ms 39000 KB Output is correct
8 Correct 253 ms 43476 KB Output is correct
9 Correct 154 ms 42308 KB Output is correct
10 Correct 190 ms 36916 KB Output is correct
11 Correct 161 ms 23148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 801 ms 18776 KB Output is correct
3 Correct 282 ms 22704 KB Output is correct
4 Correct 235 ms 22788 KB Output is correct
5 Execution timed out 1018 ms 24052 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 4 ms 596 KB Output is correct
5 Correct 2 ms 596 KB Output is correct
6 Correct 5 ms 468 KB Output is correct
7 Correct 4 ms 596 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 4 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 3 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 200 ms 38996 KB Output is correct
18 Correct 196 ms 22256 KB Output is correct
19 Correct 211 ms 42004 KB Output is correct
20 Correct 198 ms 38264 KB Output is correct
21 Correct 244 ms 43468 KB Output is correct
22 Correct 190 ms 23908 KB Output is correct
23 Correct 179 ms 38348 KB Output is correct
24 Correct 179 ms 38332 KB Output is correct
25 Correct 114 ms 23392 KB Output is correct
26 Correct 170 ms 22232 KB Output is correct
27 Correct 199 ms 22280 KB Output is correct
28 Correct 149 ms 22136 KB Output is correct
29 Correct 211 ms 43436 KB Output is correct
30 Correct 157 ms 42388 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 337 ms 38764 KB Output is correct
33 Correct 320 ms 33940 KB Output is correct
34 Correct 150 ms 19248 KB Output is correct
35 Correct 160 ms 19320 KB Output is correct
36 Correct 361 ms 39004 KB Output is correct
37 Correct 224 ms 39000 KB Output is correct
38 Correct 253 ms 43476 KB Output is correct
39 Correct 154 ms 42308 KB Output is correct
40 Correct 190 ms 36916 KB Output is correct
41 Correct 161 ms 23148 KB Output is correct
42 Correct 1 ms 212 KB Output is correct
43 Correct 801 ms 18776 KB Output is correct
44 Correct 282 ms 22704 KB Output is correct
45 Correct 235 ms 22788 KB Output is correct
46 Execution timed out 1018 ms 24052 KB Time limit exceeded
47 Halted 0 ms 0 KB -