답안 #888285

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
888285 2023-12-16T20:50:15 Z Mher777 Stranded Far From Home (BOI22_island) C++17
100 / 100
89 ms 23160 KB
/* ----------------------------- Mher777 ----------------------------- */
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <fstream>
#include <cassert>
using namespace std;

/* -------------------- Typedefs -------------------- */

typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef float fl;
typedef double db;
typedef long double ld;

/* -------------------- Usings -------------------- */

using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

/* -------------------- Defines -------------------- */

#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define all(x) (x).begin(), (x).end()

/* -------------------- Constants -------------------- */

const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18 + 5);
const ll MOD = ll(1e9 + 7);
const ll MOD2 = ll(998244353);
const ll CON = (ll)(911382323);
const ll MOD3 = (ll)(972663749);

/* -------------------- Functions -------------------- */

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}

void precision(int x) {
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(x);
}

ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

ll range_sum(ll a, ll b) {
    ll dif = a - 1, cnt = b - a + 1;
    ll ans = ((b - a + 1) * (b - a + 2)) / 2;
    ans += ((b - a + 1) * dif);
    return ans;
}

string dec_to_bin(ll a) {
    string s = "";
    for (ll i = a; i > 0; ) {
        ll k = i % 2;
        i /= 2;
        char c = k + 48;
        s += c;
    }
    if (a == 0) {
        s = "0";
    }
    reverse(all(s));
    return s;
}

ll bin_to_dec(string s) {
    ll num = 0;
    for (int i = 0; i < s.size(); i++) {
        num *= 2ll;
        num += (s[i] - '0');
    }
    return num;
}

int isPrime(ll a) {
    if (a == 1) return 0;
    for (ll i = 2; i * i <= a; i++) {
        if (a % i == 0) return 0;
    }
    return 1;
}

ll binpow(ll a, ll b) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
        }
        b >>= 1;
        a *= a;
    }
    return ans;
}

ll binpow_by_mod(ll a, ll b, ll mod) {
    if (!a) return 0;
    ll ans = 1;
    while (b) {
        if (b & 1) {
            ans *= a;
            ans %= mod;
        }
        b >>= 1;
        a *= a;
        a %= mod;
    }
    return ans;
}

/* -------------------- Solution -------------------- */
 
const int N = 200005;
ll a[N], p[N], ans[N], mx[N], sum[N];
vi g[N];
int n, m;

void make_set(int u) {
    p[u] = u;
    mx[u] = sum[u] = a[u];
    ans[u] = 1;
}

int find_set(int u) {
    if (u == p[u]) return u;
    int par = find_set(p[u]);
    if (!ans[p[u]]) ans[u] = 0;
    return p[u] = par;
}

void union_sets(int x, int y) {
    x = find_set(x);
    y = find_set(y);
    if (x == y) return;
    if (mx[x] < mx[y]) swap(x, y);
    if (mx[x] > sum[y]) ans[y] = 0;
    p[y] = x;
    sum[x] += sum[y];
}

void slv() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) cin >> a[i], make_set(i);
    vector<pair<ll, pii>> v;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        v.pub({ max(a[x],a[y]),{x,y} });
    }
    sort(all(v));
    for (auto elem : v) union_sets(elem.ss.ff, elem.ss.ss);
    for (int i = 1; i <= n; ++i) {
        find_set(i);
        cout << ans[i];
    }
}

void cs() {
    int tstc = 1;
    //cin >> tstc;
    while (tstc--) {
        slv();
    }
}

void precalc() {
    return;
}

int main() {
    fastio();
    precalc();
    //precision(0);
    cs();
    return 0;
}

Compilation message

island.cpp: In function 'll range_sum(ll, ll)':
island.cpp:94:21: warning: unused variable 'cnt' [-Wunused-variable]
   94 |     ll dif = a - 1, cnt = b - a + 1;
      |                     ^~~
island.cpp: In function 'll bin_to_dec(std::string)':
island.cpp:117:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12888 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12888 KB Output is correct
9 Correct 4 ms 12888 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 3 ms 12896 KB Output is correct
12 Correct 2 ms 13144 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 3 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 3 ms 12892 KB Output is correct
3 Correct 68 ms 18380 KB Output is correct
4 Correct 65 ms 18332 KB Output is correct
5 Correct 69 ms 22732 KB Output is correct
6 Correct 73 ms 21964 KB Output is correct
7 Correct 71 ms 21448 KB Output is correct
8 Correct 83 ms 22260 KB Output is correct
9 Correct 69 ms 22476 KB Output is correct
10 Correct 65 ms 21084 KB Output is correct
11 Correct 68 ms 20936 KB Output is correct
12 Correct 70 ms 20180 KB Output is correct
13 Correct 64 ms 20936 KB Output is correct
14 Correct 78 ms 21196 KB Output is correct
15 Correct 67 ms 22532 KB Output is correct
16 Correct 50 ms 21448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 71 ms 17476 KB Output is correct
3 Correct 76 ms 21704 KB Output is correct
4 Correct 79 ms 22280 KB Output is correct
5 Correct 66 ms 20188 KB Output is correct
6 Correct 73 ms 22004 KB Output is correct
7 Correct 69 ms 22696 KB Output is correct
8 Correct 69 ms 22732 KB Output is correct
9 Correct 56 ms 22296 KB Output is correct
10 Correct 69 ms 21416 KB Output is correct
11 Correct 68 ms 20212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 82 ms 18436 KB Output is correct
3 Correct 82 ms 22216 KB Output is correct
4 Correct 89 ms 23160 KB Output is correct
5 Correct 79 ms 22584 KB Output is correct
6 Correct 88 ms 20940 KB Output is correct
7 Correct 70 ms 21708 KB Output is correct
8 Correct 63 ms 20680 KB Output is correct
9 Correct 63 ms 20688 KB Output is correct
10 Correct 71 ms 20244 KB Output is correct
11 Correct 69 ms 20424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12888 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 3 ms 12892 KB Output is correct
5 Correct 3 ms 12892 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 12892 KB Output is correct
8 Correct 2 ms 12888 KB Output is correct
9 Correct 4 ms 12888 KB Output is correct
10 Correct 3 ms 12892 KB Output is correct
11 Correct 3 ms 12896 KB Output is correct
12 Correct 2 ms 13144 KB Output is correct
13 Correct 3 ms 12892 KB Output is correct
14 Correct 3 ms 12888 KB Output is correct
15 Correct 2 ms 12892 KB Output is correct
16 Correct 3 ms 12892 KB Output is correct
17 Correct 68 ms 18380 KB Output is correct
18 Correct 65 ms 18332 KB Output is correct
19 Correct 69 ms 22732 KB Output is correct
20 Correct 73 ms 21964 KB Output is correct
21 Correct 71 ms 21448 KB Output is correct
22 Correct 83 ms 22260 KB Output is correct
23 Correct 69 ms 22476 KB Output is correct
24 Correct 65 ms 21084 KB Output is correct
25 Correct 68 ms 20936 KB Output is correct
26 Correct 70 ms 20180 KB Output is correct
27 Correct 64 ms 20936 KB Output is correct
28 Correct 78 ms 21196 KB Output is correct
29 Correct 67 ms 22532 KB Output is correct
30 Correct 50 ms 21448 KB Output is correct
31 Correct 2 ms 12892 KB Output is correct
32 Correct 71 ms 17476 KB Output is correct
33 Correct 76 ms 21704 KB Output is correct
34 Correct 79 ms 22280 KB Output is correct
35 Correct 66 ms 20188 KB Output is correct
36 Correct 73 ms 22004 KB Output is correct
37 Correct 69 ms 22696 KB Output is correct
38 Correct 69 ms 22732 KB Output is correct
39 Correct 56 ms 22296 KB Output is correct
40 Correct 69 ms 21416 KB Output is correct
41 Correct 68 ms 20212 KB Output is correct
42 Correct 2 ms 12892 KB Output is correct
43 Correct 82 ms 18436 KB Output is correct
44 Correct 82 ms 22216 KB Output is correct
45 Correct 89 ms 23160 KB Output is correct
46 Correct 79 ms 22584 KB Output is correct
47 Correct 88 ms 20940 KB Output is correct
48 Correct 70 ms 21708 KB Output is correct
49 Correct 63 ms 20680 KB Output is correct
50 Correct 63 ms 20688 KB Output is correct
51 Correct 71 ms 20244 KB Output is correct
52 Correct 69 ms 20424 KB Output is correct
53 Correct 2 ms 12892 KB Output is correct
54 Correct 2 ms 12892 KB Output is correct
55 Correct 3 ms 13148 KB Output is correct
56 Correct 3 ms 12892 KB Output is correct
57 Correct 3 ms 12892 KB Output is correct
58 Correct 3 ms 12892 KB Output is correct
59 Correct 3 ms 12892 KB Output is correct
60 Correct 3 ms 12888 KB Output is correct
61 Correct 3 ms 12888 KB Output is correct
62 Correct 3 ms 12892 KB Output is correct
63 Correct 3 ms 12892 KB Output is correct
64 Correct 3 ms 12892 KB Output is correct
65 Correct 3 ms 12892 KB Output is correct
66 Correct 3 ms 12888 KB Output is correct
67 Correct 76 ms 22376 KB Output is correct
68 Correct 71 ms 21460 KB Output is correct
69 Correct 70 ms 21956 KB Output is correct
70 Correct 73 ms 22784 KB Output is correct
71 Correct 71 ms 21452 KB Output is correct
72 Correct 81 ms 22128 KB Output is correct
73 Correct 68 ms 22732 KB Output is correct
74 Correct 65 ms 21452 KB Output is correct
75 Correct 67 ms 22216 KB Output is correct
76 Correct 77 ms 21180 KB Output is correct
77 Correct 65 ms 21312 KB Output is correct
78 Correct 66 ms 20680 KB Output is correct
79 Correct 67 ms 22988 KB Output is correct
80 Correct 51 ms 21960 KB Output is correct
81 Correct 73 ms 21300 KB Output is correct
82 Correct 74 ms 21960 KB Output is correct
83 Correct 75 ms 22548 KB Output is correct
84 Correct 64 ms 20472 KB Output is correct
85 Correct 76 ms 22376 KB Output is correct
86 Correct 71 ms 21132 KB Output is correct
87 Correct 67 ms 21572 KB Output is correct
88 Correct 68 ms 21460 KB Output is correct
89 Correct 68 ms 20940 KB Output is correct
90 Correct 83 ms 21452 KB Output is correct
91 Correct 82 ms 20936 KB Output is correct
92 Correct 83 ms 22732 KB Output is correct
93 Correct 80 ms 21704 KB Output is correct
94 Correct 76 ms 22476 KB Output is correct
95 Correct 71 ms 22728 KB Output is correct
96 Correct 60 ms 20680 KB Output is correct
97 Correct 64 ms 19668 KB Output is correct
98 Correct 70 ms 19660 KB Output is correct
99 Correct 69 ms 19684 KB Output is correct
100 Correct 48 ms 18644 KB Output is correct
101 Correct 81 ms 22128 KB Output is correct
102 Correct 75 ms 21964 KB Output is correct
103 Correct 82 ms 20424 KB Output is correct
104 Correct 81 ms 22208 KB Output is correct