답안 #654476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654476 2022-10-31T12:44:48 Z prvocislo Stranded Far From Home (BOI22_island) C++17
25 / 100
1000 ms 29232 KB
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 2e5 + 5;
struct comp
{
    ll sum = 0;
    vector<int> s;
};
vector<comp> c(maxn);
vector<int> a(maxn), p(maxn);
int root(int u)
{
    return u == p[u] ? u : p[u] = root(p[u]);
}
int merge(int u, int v)
{
    u = root(u), v = root(v);
    if (u == v) return u;
    if (c[u].s.size() < c[v].s.size()) swap(u, v);
    p[v] = u;
    c[u].sum += c[v].sum;
    vector<int> un;
    int iu = 0, iv = 0;
    while (un.size() < c[u].s.size() + c[v].s.size())
    {
        if (iu < c[u].s.size() && (iv == c[v].s.size() || a[c[u].s[iu]] < a[c[v].s[iv]])) un.push_back(c[u].s[iu++]);
        else un.push_back(c[v].s[iv++]);
    }
    c[u].s = un;
    return u;
}
bool cmp(int i, int j)
{
    return a[i] < a[j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int> > w;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        w.push_back({ a[i], i });
        c[i].sum = a[i];
        p[i] = i;
    }
    vector<vector<int> > g(n);
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        if (make_pair( a[u], u ) > make_pair( a[v], v )) swap(u, v);
        c[u].s.push_back(v);
        g[v].push_back(u);
    }
    for (int i = 0; i < n; i++) sort(c[i].s.begin(), c[i].s.end(), cmp);
    vector<int> de(n, -1);
    sort(w.begin(), w.end());
    for (pair<int, int> p : w)
    {
        int u = p.second, cm = u;
        for (int v : g[u]) cm = merge(cm, v);
        vector<int> bad = c[cm].s;
        c[cm].s.clear();
        for (int i : bad) if (i != u) c[cm].s.push_back(i);
        if (!c[cm].s.empty() && a[c[cm].s[0]] <= c[cm].sum) de[u] = c[cm].s[0];
    }
    reverse(w.begin(), w.end());
    vector<bool> ans(n, false);
    for (pair<int, int> p : w)
    {
        int u = p.second;
        if (p == w[0]) ans[u] = true;
        else if (de[u] != -1) ans[u] = ans[de[u]];
    }
    for (int i = 0; i < n; i++) cout << "01"[ans[i]];
    cout << "\n";
    return 0;
}

Compilation message

island.cpp: In function 'int merge(int, int)':
island.cpp:42:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         if (iu < c[u].s.size() && (iv == c[v].s.size() || a[c[u].s[iu]] < a[c[v].s[iv]])) un.push_back(c[u].s[iu++]);
      |             ~~~^~~~~~~~~~~~~~~
island.cpp:42:39: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         if (iu < c[u].s.size() && (iv == c[v].s.size() || a[c[u].s[iu]] < a[c[v].s[iv]])) un.push_back(c[u].s[iu++]);
      |                                    ~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 5 ms 8148 KB Output is correct
4 Correct 8 ms 8276 KB Output is correct
5 Correct 7 ms 8276 KB Output is correct
6 Correct 8 ms 8316 KB Output is correct
7 Correct 7 ms 8276 KB Output is correct
8 Correct 8 ms 8276 KB Output is correct
9 Correct 11 ms 8444 KB Output is correct
10 Correct 6 ms 8308 KB Output is correct
11 Correct 7 ms 8348 KB Output is correct
12 Correct 7 ms 8276 KB Output is correct
13 Correct 6 ms 8280 KB Output is correct
14 Correct 7 ms 8304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8148 KB Output is correct
2 Correct 5 ms 8148 KB Output is correct
3 Correct 211 ms 27296 KB Output is correct
4 Correct 236 ms 26752 KB Output is correct
5 Correct 202 ms 26032 KB Output is correct
6 Correct 261 ms 26588 KB Output is correct
7 Correct 256 ms 26640 KB Output is correct
8 Execution timed out 1025 ms 27020 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8148 KB Output is correct
2 Correct 300 ms 24912 KB Output is correct
3 Correct 276 ms 24992 KB Output is correct
4 Correct 241 ms 29232 KB Output is correct
5 Correct 194 ms 28496 KB Output is correct
6 Correct 293 ms 25104 KB Output is correct
7 Correct 222 ms 29220 KB Output is correct
8 Correct 226 ms 29168 KB Output is correct
9 Correct 119 ms 28436 KB Output is correct
10 Correct 216 ms 22988 KB Output is correct
11 Correct 260 ms 24716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8060 KB Output is correct
2 Correct 705 ms 24992 KB Output is correct
3 Correct 345 ms 24896 KB Output is correct
4 Correct 298 ms 24984 KB Output is correct
5 Correct 324 ms 24904 KB Output is correct
6 Execution timed out 1004 ms 24688 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8148 KB Output is correct
2 Correct 4 ms 8148 KB Output is correct
3 Correct 5 ms 8148 KB Output is correct
4 Correct 8 ms 8276 KB Output is correct
5 Correct 7 ms 8276 KB Output is correct
6 Correct 8 ms 8316 KB Output is correct
7 Correct 7 ms 8276 KB Output is correct
8 Correct 8 ms 8276 KB Output is correct
9 Correct 11 ms 8444 KB Output is correct
10 Correct 6 ms 8308 KB Output is correct
11 Correct 7 ms 8348 KB Output is correct
12 Correct 7 ms 8276 KB Output is correct
13 Correct 6 ms 8280 KB Output is correct
14 Correct 7 ms 8304 KB Output is correct
15 Correct 5 ms 8148 KB Output is correct
16 Correct 5 ms 8148 KB Output is correct
17 Correct 211 ms 27296 KB Output is correct
18 Correct 236 ms 26752 KB Output is correct
19 Correct 202 ms 26032 KB Output is correct
20 Correct 261 ms 26588 KB Output is correct
21 Correct 256 ms 26640 KB Output is correct
22 Execution timed out 1025 ms 27020 KB Time limit exceeded
23 Halted 0 ms 0 KB -