QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#126700#4246. Cactus is MoneyminhcoolML 6ms25744kbC++175.0kb2023-07-18 21:35:202023-07-18 21:35:23

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-18 21:35:23]
  • 评测
  • 测评结果:ML
  • 用时:6ms
  • 内存:25744kb
  • [2023-07-18 21:35:20]
  • 提交

answer

#define local
#ifndef local
#include ""
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
//#define mp make_pair

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 3e5 + 5;

const int oo = 1e18 + 7, mod = 1e9 + 7;

mt19937 rng(1);

int rnd(int l, int r){
	int temp = rng() % (r - l + 1);
	return abs(temp) + l;
}

ii diff(ii a, ii b){
	return {a.fi - b.fi, a.se - b.se};
}

int cross(ii a, ii b){
	return a.fi * b.se - a.se * b.fi;
}

vector<ii> rot(vector<ii> v){
	int pos = 0;
	for(int i = 1; i < v.size(); i++){
		if(v[pos].se > v[i].se || (v[pos].se == v[i].se && v[pos].fi > v[i].fi)) pos = i;
	}
	vector<ii> v2;
	for(int i = pos; i < v.size(); i++) v2.pb(v[i]);
	for(int i = 0; i < pos; i++) v2.pb(v[i]);
	return v2;
}

vector<ii> mincow(vector<ii> a, vector<ii> b){
	a = rot(a), b = rot(b);
//	for(auto it : a) cout << "OK1 " << it.fi << " " << it.se << "\n";
//	for(auto it : b) cout << "OK2 " << it.fi << " " << it.se << "\n";
	a.pb(a[0]), a.pb(a[1]);
	b.pb(b[0]), b.pb(b[1]);
	int itr1 = 0, itr2 = 0;
	vector<ii> c;
	while((itr1 < a.size() - 2) || (itr2 < b.size() - 2)){
		c.pb({a[itr1].fi + b[itr2].fi, a[itr1].se + b[itr2].se});
		int temp = cross(diff(a[itr1 + 1], a[itr1]), diff(b[itr2 + 1], b[itr2]));
	//	cout << a.size() << " " << b.size() << " " << itr1 << " " << itr2 << "\n";
		if((temp >= 0) && itr1 < a.size() - 2) itr1++;
		if((temp <= 0) && itr2 < b.size() - 2) itr2++;
		//if(temp <= 0 && itr2 < b.size() - 2) itr2++;
	}
	return c;
}

int n, m;

vector<ii> vc;

bool ccw(ii a, ii b, ii c){// true if (a, b, c) counter clockwise
    int val = cross(diff(b, a), diff(c, b));
    if(val > 0) return 1;
    return 0;
}

ii mini;

bool cmp(ii a, ii b){
    return ccw(mini, a, b);
}

vector<ii> cvh(vector<ii> a){
    int pos = 0;
    for(int i = 1; i < a.size(); i++){
        if(a[i].fi < a[pos].fi || (a[i].fi == a[pos].fi && a[i].se < a[pos].se)) pos = i;
    }
    swap(a[a.size() - 1], a[pos]);
    vector<ii> v;
    mini = a.back();
    v.pb(a.back());
    a.pop_back();
    sort(a.begin(), a.end(), cmp);
    for(auto it : a){
        while(v.size() >= 2 && !ccw(v[v.size() - 2], v[v.size() - 1], it)) v.pop_back();
        v.pb(it);
    }
    return v;
}

vector<iiii> edges;

vector<ii> Adj[N];
bool vis[N], ck[N], incyc[N];
ii par[N];
int le[N], ri[N], cnt;

bool anc(int x, int y){
    return (le[x] <= le[y] && ri[x] >= ri[y]);
}

void dfs(int u){
    cnt++;
    le[u] = cnt;
    vis[u] = 1;
    for(auto it : Adj[u]){
        int v = it.fi, ind = it.se;
        if(vis[v]) continue;
        ck[ind] = 1;
        par[v] = {u, ind};
        dfs(v);
    }
    ri[u] = cnt;
}

int counter = 0;
vector<ii> cvhs[N];

vector<ii> get(int l, int r){
    if(l == r) return cvhs[l];
    int mid = (l + r) >> 1;
    return mincow(get(l, mid), get(mid + 1, r));
}

#ifdef local
void process(){
    cin >> n >> m;
    for(int i = 1; i <= m; i++){
        int x, y, a, b;
        cin >> x >> y >> a >> b;
        edges.pb({{x, y}, {a, b}});
        Adj[x].pb({y, i - 1});
        Adj[y].pb({x, i - 1});
    }
    for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i);
    //cout << "OKAY\n";
    //exit(0);
    for(int i = 0; i < m; i++){
        if(ck[i]) continue;
        int x = edges[i].fi.fi, y = edges[i].fi.se;
        //cout << i << " " << x << " " << y << "\n";
        vector<ii> v;
        while(!anc(x, y)){
            incyc[par[x].se] = 1;
            v.pb(edges[par[x].se].se);
            x = par[x].fi;
        }
        while(!anc(y, x)){
            incyc[par[y].se] = 1;
            v.pb(edges[par[y].se].se);
            y = par[y].fi;
        }
        incyc[i] = 1;
        v.pb(edges[i].se);
        vector<ii> points;
        int tol1 = 0, tol2 = 0;
        for(auto it : v){
            tol1 += it.fi, tol2 += it.se;
        }
        for(auto it : v) points.pb({tol1 - it.fi, tol2 - it.se});
        //for(auto it : v) cout << it.fi << " " << it.se << "\n";
        points = cvh(points);
        //for(auto it : v) cout << it.fi << " " << it.se << "\n";
        counter++;
        cvhs[counter] = points;
    }
    ii temp = {0, 0};
    for(int i = 0; i < m; i++){
        if(!incyc[i]){
            temp.fi += edges[i].se.fi, temp.se += edges[i].se.se;
        }
    }
    //cout << temp.fi << " " << temp.se << "\n";
    vector<ii> v = get(1, counter);
   // cout << v.size() << "\n";
    int answer = oo;
    for(auto it : v){
        //cout << it.fi << " " << it.se << "\n";
        answer = min(answer, (it.fi + temp.fi) * (it.se + temp.se));
    }
    cout << answer << "\n";
}

signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	freopen("kek.inp", "r", stdin);
//	freopen("kek.out", "w", stdout);
	process();
}
#endif

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 23688kb

input:

3 3
1 2 0 1000
2 3 0 1000
3 1 1 1

output:

0

result:

ok 1 number(s): "0"

Test #2:

score: 0
Accepted
time: 6ms
memory: 23708kb

input:

5 5
1 2 666 10
2 3 555 1000
3 1 444 345
1 4 222 234
2 5 333 123

output:

1185480

result:

ok 1 number(s): "1185480"

Test #3:

score: 0
Accepted
time: 3ms
memory: 23720kb

input:

5 6
1 3 12316 13729
1 2 171 10309
5 1 47389 7369
2 4 43318 36867
1 4 30728 43835
5 3 24437 31639

output:

6732185824

result:

ok 1 number(s): "6732185824"

Test #4:

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

input:

6 6
5 2 36032 49949
4 5 8963 9741
3 4 4004 35098
4 1 14459 30350
4 6 39612 8568
1 5 8645 16098

output:

11617618224

result:

ok 1 number(s): "11617618224"

Test #5:

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

input:

6 6
6 1 1516 16290
3 5 47834 15228
5 1 14795 44496
2 6 21296 36977
6 3 42659 16631
4 3 9808 31313

output:

13124412318

result:

ok 1 number(s): "13124412318"

Test #6:

score: 0
Accepted
time: 4ms
memory: 23692kb

input:

7 7
1 7 42781 13704
7 3 48779 17985
6 4 27969 24986
4 7 33333 35700
5 7 4859 49960
6 2 23927 33500
6 1 11232 15327

output:

24803495714

result:

ok 1 number(s): "24803495714"

Test #7:

score: 0
Accepted
time: 3ms
memory: 23728kb

input:

10 11
7 3 43798 8096
5 7 36600 4126
2 6 20599 15893
9 6 7541 5621
4 9 22047 10608
5 10 21235 2700
1 10 19260 8862
4 3 22407 37504
5 1 12867 1738
1 8 48480 15236
2 5 43525 13679

output:

19944198324

result:

ok 1 number(s): "19944198324"

Test #8:

score: 0
Accepted
time: 1ms
memory: 23692kb

input:

10 12
10 2 21765 14299
4 2 8316 29600
3 2 36018 33286
4 5 30741 46828
9 7 13354 18461
9 5 11896 14216
6 1 35705 34008
1 9 41496 21860
7 5 37709 34178
8 7 1595 27497
6 9 12139 37471
3 5 43310 12734

output:

39767313936

result:

ok 1 number(s): "39767313936"

Test #9:

score: 0
Accepted
time: 3ms
memory: 23736kb

input:

10 13
10 1 28967 29646
9 1 45852 47509
6 1 2590 36591
5 4 21715 40134
1 5 44167 42132
2 10 27289 12132
5 7 26720 1258
1 3 2762 28223
3 6 6966 48096
5 8 23536 33618
7 8 28326 9456
1 2 4885 15100
5 9 41414 32957

output:

43567826244

result:

ok 1 number(s): "43567826244"

Test #10:

score: 0
Accepted
time: 1ms
memory: 25744kb

input:

20 28
18 19 35583 99
15 18 30705 19256
14 18 20288 26882
18 4 39622 18793
11 7 47613 25425
8 18 33445 7046
18 13 37838 47190
18 1 47524 18152
8 10 20627 40858
18 6 49396 47654
9 18 9453 36001
20 18 33280 38985
11 18 47686 42244
1 20 8726 35210
14 6 20998 13452
18 10 10397 48525
19 4 45811 48722
5 17...

output:

196145757738

result:

ok 1 number(s): "196145757738"

Test #11:

score: 0
Accepted
time: 1ms
memory: 23796kb

input:

20 28
1 11 29270 12003
11 14 39731 27230
4 11 43657 44868
13 10 37887 17666
8 6 12758 4662
12 18 34016 15740
12 11 1123 44690
1 14 1866 31755
17 7 12441 26285
3 10 29159 11042
4 19 22612 12647
2 3 43899 27826
17 3 26727 7304
20 5 32807 49683
16 3 40800 14397
3 5 21244 13387
11 3 39919 35610
15 9 944...

output:

135255186000

result:

ok 1 number(s): "135255186000"

Test #12:

score: 0
Accepted
time: 1ms
memory: 23888kb

input:

500 627
218 441 9330 38888
394 403 39336 6683
81 319 10978 28288
157 204 27638 7127
58 38 7029 7446
168 100 23915 46064
180 151 42120 1549
18 238 15877 34786
37 259 37301 2159
463 185 4155 13849
77 355 5111 14848
62 486 19786 48858
132 408 41592 45835
245 378 46373 21496
291 20 36847 18682
435 213 3...

output:

115468900928208

result:

ok 1 number(s): "115468900928208"

Test #13:

score: 0
Accepted
time: 3ms
memory: 23848kb

input:

500 655
118 73 5102 36606
387 191 18264 17089
462 226 6016 40383
215 303 3543 6165
95 192 19518 19250
37 430 21505 26348
406 484 45283 8029
446 64 32626 30683
432 146 22720 12184
1 145 4822 43486
169 355 44960 12596
399 372 1339 28076
452 387 11774 33758
186 72 47444 20235
145 61 30207 39522
87 419 ...

output:

126690228324902

result:

ok 1 number(s): "126690228324902"

Test #14:

score: -100
Memory Limit Exceeded

input:

500 499
11 127 37123 28858
439 253 39067 7779
148 142 5215 35775
441 354 15081 38415
145 463 8601 8508
400 332 23071 25635
193 124 33687 31694
154 449 45482 46872
499 469 49487 28780
24 246 48364 48917
458 397 3906 33392
130 108 13072 11058
235 406 11881 17681
20 172 35252 25687
81 24 41900 11751
49...

output:


result: