QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#757118#5811. Wi-fi TowersjanY28 ✓46ms5756kbC++204.8kb2024-11-17 00:25:272024-11-17 00:25:27

Judging History

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

  • [2024-11-17 00:25:27]
  • 评测
  • 测评结果:28
  • 用时:46ms
  • 内存:5756kb
  • [2024-11-17 00:25:27]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define ld long double
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define rev(x) reverse(x.begin(), x.end())
#define fi first
#define se second
#define pb push_back
#define PI 3.14159265359
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second < b.second);}
#define sortpairbysec(x) sort(all(x), sortbysec)
bool sortcond(const pair<int,int> &a,const pair<int,int> &b){
    if (a.fi != b.fi){
        return a.fi < b.fi;
    } else {
        return a.se > b.se;
    }
}
struct myComp {
    constexpr bool operator()( pii const& a, pii const& b) const noexcept
    {
        if (a.first != b.first){
            return a.first < b.first;
        } else {
            return a.second > b.second;
        }
    }
};
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rng(ll lim) {
    uniform_int_distribution<ll> uid(0,lim-1);
    return uid(rang);
}

const int mod = 998244353;
const int N = 3e5, M = N;
const ll inf = 1e18;
//=======================
struct edmond {

    vector<vector<ll>> capacity;
    vector<vector<int>> adj;
    int graph_size;

    void init(int siz){
        graph_size = siz;
        capacity.resize(siz, vector<ll>(siz));
        adj.resize(siz);
    }

    void add_edge(int u, int v, ll cap){
        adj[u].pb(v);
        adj[v].pb(u);
        capacity[u][v] = cap;
    }

    ll bfs(int s, int t, vector<int>& parent) {
        fill(parent.begin(), parent.end(), -1);
        parent[s] = -2;
        queue<pair<int, ll>> q; // edmond karp
        // stack<pair<int, ll>> q; // ford fulkerson
        q.push({s, inf});

        while (!q.empty()) {
            int cur = q.front().first;
            ll flow = q.front().second;
            q.pop();

            for (int next : adj[cur]) {
                if (parent[next] == -1 && capacity[cur][next]) {
                    parent[next] = cur;
                    ll new_flow = min(flow, capacity[cur][next]);
                    if (next == t) return new_flow;
                    q.push({next, new_flow});
                }
            }
        }

        return 0;
    }

    ll maxflow(int s, int t) {
        ll flow = 0;
        vector<int> parent(graph_size);
        ll new_flow;

        while (true) {
            new_flow = bfs(s, t, parent);
            if (new_flow == 0) break;
            flow += new_flow;
            int cur = t;
            while (cur != s) {
                int prev = parent[cur];
                capacity[prev][cur] -= new_flow;
                capacity[cur][prev] += new_flow;
                cur = prev;
            }
        }

        return flow;
    }
};
//=======================
// & - bitwise AND; | - bitwise OR; ^ - bitwise XOR
// cout.precision(7);
// next_permutation(arr.begin(), arr.end());
// long long long long long long long long long long long long long long long long long long long long long long long long long long long
// priority_queue<int, vector<int>, greater<int>> a; (min heap)
// ll hash1 = hash<string>{}(to_string(1));
// always lower_bound
// __builtin_clz(n) count leading zeros

vl a;
ll n, m, k, q;

ll dist(ll x1, ll y1, ll x2, ll y2){
    return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

void solve(int tc) {
    int i, j;
    cin >> n;
    edmond flow;
    flow.init(n+2);
    int s = n;
    int t = n+1;

    vpii coords(n);
    vi radius(n);

    int offset = 10001;
    fo(i, n){
        int x, y, r, v;
        cin >> x >> y >> r >> v;
        coords[i] = {x, y};
        radius[i] = r;
        flow.add_edge(s, i, offset);
        flow.add_edge(i, t, -v + offset);
    }

    fo(i, n){
        fo(j, n){
            if (i == j) continue;
            int x1 = coords[i].fi;
            int y1 = coords[i].se;
            int x2 = coords[j].fi;
            int y2 = coords[j].se;
            if (dist(x1, y1, x2, y2) <= radius[i]*radius[i]){
                flow.add_edge(i, j, inf);
            }
        }
    }
    cout << "Case #" << tc << ": " << offset*n - flow.maxflow(s, t) << "\n";
}
 
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    cin >> t;
    int i;
    fo(i, t) {
        solve(i+1);
    }
    return 0;
}

详细

Subtask #1:

score: 3
Accepted

Test #1:

score: 3
Accepted
time: 1ms
memory: 3716kb

input:

55
15
10 12 45 -1
9 5 50 1
5 20 41 1
11 8 50 1
20 13 44 1
2 0 45 -1
5 4 47 -1
14 13 42 -1
19 1 47 -1
8 0 41 -1
8 16 40 -1
15 11 42 1
8 8 42 1
2 9 50 1
0 10 44 1
15
872 2191 2 -386
-2071 -3796 1 -568
4237 -5305 6742 275
-2307 -6269 1 -148
6875 -19 461 -519
-9871 -3500 64 -306
-2576 -5709 25 686
431 8...

output:

Case #1: 1
Case #2: 3091
Case #3: 923
Case #4: 651
Case #5: 1387
Case #6: 1319
Case #7: 1
Case #8: 747
Case #9: 0
Case #10: 1443
Case #11: 2
Case #12: 0
Case #13: 1746
Case #14: 1533
Case #15: 687
Case #16: 1851
Case #17: 2140
Case #18: 886
Case #19: 673
Case #20: 0
Case #21: 1772
Case #22: 0
Case #...

result:

ok 55 lines

Subtask #2:

score: 25
Accepted

Test #2:

score: 25
Accepted
time: 46ms
memory: 5756kb

input:

55
5
0 -1 7 10
0 1 7 10
5 0 1 -15
10 0 6 10
15 1 2 -20
171
46 50 3 3
30 6 8 2
14 30 8 2
10 10 8 4
48 28 1 -2
18 18 9 3
52 12 1 -2
54 6 10 4
26 54 10 4
24 36 1 -1
30 14 3 1
4 36 1 -1
40 4 1 -2
14 14 9 4
52 40 1 -3
20 48 1 -2
50 6 8 3
16 16 1 -3
10 42 3 2
50 38 7 3
44 52 1 -2
4 48 1 -2
16 52 1 -1
32 5...

output:

Case #1: 5
Case #2: 24
Case #3: 18455
Case #4: 46
Case #5: 34885
Case #6: 12211
Case #7: 4653
Case #8: 3560
Case #9: 16236
Case #10: 64
Case #11: 12885
Case #12: 18102
Case #13: 17
Case #14: 10
Case #15: 3824
Case #16: 2589
Case #17: 3949
Case #18: 1
Case #19: 0
Case #20: 28
Case #21: 40141
Case #22...

result:

ok 55 lines

Extra Test:

score: 0
Extra Test Passed