QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#547609#4209. Stranded Far From Homemakrav0 72ms34608kbC++202.5kb2024-09-04 23:57:432024-09-04 23:57:44

Judging History

你现在查看的是最新测评结果

  • [2024-09-04 23:57:44]
  • 评测
  • 测评结果:0
  • 用时:72ms
  • 内存:34608kb
  • [2024-09-04 23:57:43]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

struct dsu {
    int n;
    vector<int> par, siz, sum, cnt, mx, can;
    vector<vector<int>> sub;
    dsu() = default;
    dsu(int n_, vector<int> a) {
        n = n_;
        par.assign(n, 0);
        iota(all(par), 0);
        sum = a;
        siz.assign(n, 1);
        cnt.assign(n, 1);
        can.assign(n, 1);
        sub.assign(n, {});
        for (int i = 0; i < n; i++) {
            sub[i].pb(i);
        }
        mx = a;
    }

    int get(int v) {
        return (par[v] == v ? v : par[v] = get(par[v]));
    }

    void merge(int u, int v) {
        u = get(u);
        v = get(v);
        if (u == v) return;
        if (mx[u] < mx[v]) swap(u, v);
        int newcnt = cnt[u];
        if (sum[v] >= mx[u]) {
            newcnt += cnt[v];
        } else {
            for (auto &U : sub[v]) {
                can[U] = 0;
            }
            sub[v].clear();
        }

        if (siz[u] < siz[v]) swap(u, v);
        par[v] = u;
        mx[u] = max(mx[u], mx[v]);
        cnt[u] = newcnt;
        siz[u] += siz[v];
        sum[u] += sum[v];
        for (auto &U : sub[v]) sub[u].pb(U);
        sub[v].clear();
    }
};

void solve() {
    int n, m; cin >> n >> m;
    vector<int> c(n);
    for (int i = 0; i < n; i++) cin >> c[i];
    vector<int> ord(n);
    iota(all(ord), 0);
    sort(all(ord), [&](int i, int j){return c[i] < c[j];});
    vector<vector<int>> edges(n);
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v;
        u--; v--;
        if (c[u] < c[v]) swap(u, v);
        edges[u].pb(v);
    }
    dsu d(n, c);
    for (int i = 0; i < sz(ord); i++) {
        int nxt = i;
        while (nxt < n && c[ord[i]] == c[ord[nxt]]) nxt++;
        for (int j = i; j < nxt; j++) {
            for (int v : edges[ord[j]]) {
                d.merge(v, ord[j]);
            }
        }
        i = nxt - 1;
    }
    for (auto &u : d.can) cout << u;
    cout << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3844kb

input:

1622 1998
29021716 740464354 721037601 759718475 973636178 59068917 294028640 285332651 203821680 397646208 488684783 448548424 565347277 112938323 832704692 837437153 508335516 167646888 798998153 86605661 820823253 705498382 116513873 672806499 522392461 568294614 457655230 647498964 577669416 506...

output:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000...

result:

wrong answer 1st lines differ - expected: '011110101110001100101101111110...1000100110101000000111111011011', found: '000000000000000000000000000000...0000000000000000000000000000000'

Subtask #2:

score: 0
Wrong Answer

Test #15:

score: 10
Accepted
time: 61ms
memory: 34608kb

input:

200000 199999
100000000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok single line: '100000000000000000000000000000...0000000000000000000000000000000'

Test #16:

score: 0
Wrong Answer
time: 65ms
memory: 33656kb

input:

200000 199999
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...

output:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

wrong answer 1st lines differ - expected: '111111111111111111111111111111...0000000000000000000000000000000', found: '000000000000000000000000000000...0000000000000000000000000000000'

Subtask #3:

score: 0
Wrong Answer

Test #30:

score: 0
Wrong Answer
time: 72ms
memory: 32164kb

input:

199999 199998
758475118 758475116 758475114 758475112 758475110 758475108 758475106 758475104 758475102 758475100 758475098 758475096 758475094 758475092 758475090 758475088 758475086 758475084 758475082 758475080 758475078 758475076 758475074 758475072 758475070 758475068 758475066 758475064 758475...

output:

100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

wrong answer 1st lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111111', found: '100000000000000000000000000000...0000000000000000000000000000001'

Subtask #4:

score: 0
Wrong Answer

Test #39:

score: 0
Wrong Answer
time: 61ms
memory: 24564kb

input:

155555 200000
473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735421 473735...

output:

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

wrong answer 1st lines differ - expected: '111111111111111111111111111111...1111111111111111111111111111100', found: '000000000000000000000000000000...0000000000000000000000000000000'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%