QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#166951#6517. Computational Geometryucup-team134#AC ✓789ms785080kbC++144.4kb2023-09-06 21:33:452023-09-06 21:33:46

Judging History

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

  • [2023-09-06 21:33:46]
  • 评测
  • 测评结果:AC
  • 用时:789ms
  • 内存:785080kb
  • [2023-09-06 21:33:45]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

void test(){
	int n=ri();
	vector<pair<int,int>> c(n);
	rd(c);
	for(int i=0;i<n;i++){
		c.pb(c[i]);
	}
	auto dist=[&](int a,int b){
		return (ll)(c[a].f-c[b].f)*(c[a].f-c[b].f)+(ll)(c[a].s-c[b].s)*(c[a].s-c[b].s);
	};
	int N=2*n;
	vector<vector<ll>> dp(N,vector<ll>(N));
	for(int i=0;i<N;i++){
		for(int j=i-1;j>=0;j--){
			//printf("%i %i: %lld\n",j,i,dist(i,j));
			dp[j][i]=max(dp[j][i],dist(i,j));
			dp[j][i]=max(dp[j][i],dp[j+1][i]);
			dp[j][i]=max(dp[j][i],dp[j][i-1]);
		}
	}
	ll oo=LLONG_MAX/3;
	for(int i=0;i<N;i++){
		dp[i][i]=oo;
		dp[i][i+1]=oo;
		for(int j=i+2;j<N;j++){
			ll x1=c[j].f-c[i].f,y1=c[j].s-c[i].s,x2=c[i+1].f-c[i].f,y2=c[i+1].s-c[i].s;
			ll crs=x1*y2-x2*y1;
			if(crs==0){
				dp[i][j]=oo;
			}
			else{
				break;
			}
		}
	}
	ll mn=LLONG_MAX;
	for(int i=0;i<n;i++){
		for(int j=i+2;j<n;j++){
			if(i==0&&j==n-1){
				continue;
			}
			ll val=dp[i][j]+dp[j][i+n];
			//printf("%i %i: %lld   %lld  %lld\n",i,j,val,dp[i][j],dp[j][i+n]);
			mn=min(mn,val);
		}
	}
	printf("%lld\n",mn);
}
int main()
{
	int t=ri();
	while(t--){
		test();
	}
	return 0;
}

详细

Test #1:

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

input:

2
4
1 0
2 0
1 1
0 0
6
10 4
9 7
5 7
4 5
6 4
9 3

output:

4
44

result:

ok 2 number(s): "4 44"

Test #2:

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

input:

713
8
8 25
3 15
0 5
10 0
19 2
24 6
23 15
15 34
8
25 16
18 25
10 32
1 23
0 14
21 0
27 2
32 6
7
16 15
8 20
1 16
0 12
16 0
21 1
24 5
7
15 1
18 0
24 8
27 15
4 19
0 17
7 8
4
10 20
0 30
15 0
14 10
6
15 0
24 10
21 14
12 14
7 11
0 3
7
18 7
16 9
12 10
6 9
0 4
5 0
15 1
9
0 23
8 13
14 6
24 0
34 1
41 11
37 20
1...

output:

1075
1389
706
687
1550
497
300
1668
471
162
519
190
786
983
367
930
580
524
509
275
617
298
146
1330
494
965
599
1321
866
1210
233
398
560
1548
871
938
366
500
371
1118
1222
1994
712
586
858
624
697
575
1274
882
1035
406
934
670
990
1231
513
2871
939
2735
1610
834
721
585
203
198
1666
617
1166
326
2...

result:

ok 713 numbers

Test #3:

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

input:

723
6
219724071 0
454078946 131628774
497404433 165947891
427997418 299842932
68283732 510015817
0 327227140
5
277969751 0
576739203 275664810
244855879 638262097
13873538 700473186
0 59956198
10
69526931 509564969
0 395765436
101436487 0
273066511 46581979
904969235 467379058
942000353 535129295
93...

output:

320990950510053393
818929519958899381
1129629590903770087
711353303900820471
683190682500395857
594439231930042527
659610359567672203
1233154227545010165
845514798756141601
410893515758460170
293647337551438590
889581785464512646
1220017957053127490
1180615726625079978
993125871111020743
88416805922...

result:

ok 723 numbers

Test #4:

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

input:

50
100
10788090 640461343
6200823 619327060
0 588075358
2272688 571167135
10484649 531645155
23408105 495027985
37809823 457353729
50543748 426748658
65612394 391936420
74144467 375312692
92238239 342008581
110825102 314274629
136945272 275387892
150625359 258378302
176177538 227408568
211850028 189...

output:

1000855227786024811
909070606999097417
1017431101951290615
990111498358638326
950728988782865680
962774560452779714
996309366656593850
986848706669893356
1081700839718966666
773766023115436171
992970791950402937
973701678270317636
997205411196945405
983632880388713682
992033016531185503
952505046981...

result:

ok 50 numbers

Test #5:

score: 0
Accepted
time: 51ms
memory: 34720kb

input:

5
1000
878526908 228987227
879855378 230541662
883056137 234320630
885582660 237315912
888209996 240551797
891283004 244370572
893274852 246878195
896391978 250849089
898459829 253488754
901495898 257421882
904401963 261232268
906943144 264566136
909037936 267445789
911696142 271101695
913243951 273...

output:

992531084409938036
941345840855103718
1001527316088973221
994659442447419455
991404250855675335

result:

ok 5 number(s): "992531084409938036 94134584085...442447419455 991404250855675335"

Test #6:

score: 0
Accepted
time: 789ms
memory: 785080kb

input:

1
5000
967641745 600438802
967481178 600923111
967219084 601713440
967049837 602223711
966911813 602639084
966682840 603325811
966509662 603840159
966373844 604241989
966137283 604938445
965876558 605705659
965650625 606370144
965512876 606773817
965436585 606996596
965168879 607776452
965094451 607...

output:

977443873239086022

result:

ok 1 number(s): "977443873239086022"

Test #7:

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

input:

3
4
0 0
1000000000 0
1000000000 1000000000
0 1000000000
5
0 0
1 0
1000000000 0
1000000000 1000000000
0 1000000000
6
13 0
51 0
999999989 0
1000000000 999999995
999999995 1000000000
0 999999996

output:

4000000000000000000
3000000000000000001
2999999962000002754

result:

ok 3 number(s): "4000000000000000000 3000000000000000001 2999999962000002754"