QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#57982#3894. Generator GridBeevo#WA 3ms4512kbC++231.8kb2022-10-24 02:42:532022-10-24 02:42:54

Judging History

This is the latest submission verdict.

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-24 02:42:54]
  • Judged
  • Verdict: WA
  • Time: 3ms
  • Memory: 4512kb
  • [2022-10-24 02:42:53]
  • Submitted

answer

#include <bits/stdc++.h>

#define el '\n'
#define ll long long
#define ld long double

#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

const int N = 1e5 + 5;


struct DSU {
    vector<int> sz, par, lit;

    DSU() {
        sz.resize(N);
        par.resize(N);
        lit.resize(N);

        for (int i = 0; i < N; i++)
            par[i] = i, sz[i] = 1;
    }

    int findSet(int u) {
        if (u == par[u])
            return u;

        return par[u] = findSet(par[u]);
    }

    void unionSet(int u, int v) {
        u = findSet(u);
        v = findSet(v);

        if (u != v) {
            if (sz[u] < sz[v])
                swap(u, v);

            par[v] = u;
            sz[u] += sz[v];
            lit[u] |= lit[v];
        }
    }
} dsu;

void testCase() {
    int n, m;
    cin >> n >> m;

    ll c;
    int u;
    vector<pair<int, pair<int, bool>>> v;
    for (int i = 0; i < m; i++) {
        cin >> u >> c;

        u--;

        v.push_back({c, {u, 0}});
    }

    for (int i = 0; i < n; i++) {
        cin >> c;

        v.push_back({c, {i, 1}});
    }

    sort(v.begin(), v.end());

    ll sum = 0;
    for (auto &i: v) {
        if (!i.second.second) {
            if (dsu.lit[dsu.findSet(i.second.first)])
                continue;

            sum += i.first;

            dsu.lit[dsu.findSet(i.second.first)] = 1;
        }
        else {
            if (dsu.lit[dsu.findSet(i.second.first)] && dsu.lit[dsu.findSet((i.second.first + 1)) % n])
                continue;

            sum += i.first;

            dsu.unionSet(i.second.first, (i.second.first + 1) % n);
        }
    }

    cout << sum;
}

signed main() {
    Beevo

    int T = 1;
//    cin >> T;

    while (T--)
        testCase();

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 4512kb

input:

3 2
1 100
2 200
150 300 150

output:

400

result:

ok single line: '400'

Test #2:

score: 0
Accepted
time: 0ms
memory: 4464kb

input:

3 2
1 100
2 200
300 300 150

output:

450

result:

ok single line: '450'

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 4512kb

input:

100 1
1 100
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 ...

output:

1100

result:

wrong answer 1st lines differ - expected: '1090', found: '1100'