QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#969#639316#9458. Triangulationhos_lyric275307894aFailed.2024-10-13 20:21:012024-10-13 20:21:01

詳細信息

Extra Test:

Accepted
time: 280ms
memory: 64828kb

input:

70
18
0 81
1 64
2 49
3 36
4 25
5 16
6 9
7 4
8 1
9 0
10 1
11 4
12 9
13 16
14 25
15 36
16 49
17 64
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0...

output:

0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 35357670
0 3...

result:

ok 70 lines

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639316#9458. Triangulation275307894aAC ✓89ms101664kbC++143.7kb2024-10-13 18:56:462024-10-13 18:56:50

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=18+5,M=(1<<18)+5,K=1000+5,mod=1e9+7,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n;
using cp=complex<db>;
cp A[N];
db cross(cp x,cp y){return x.real()*y.imag()-x.imag()*y.real();}
bool above(cp x,cp y,cp z){return cross(y-x,z-y)>0;}
int st[N],sh;
int p[N];
struct info{
	int x;ll w;
	info operator +(const info &B){
		if(x^B.x) return x<B.x?(info){x,w}:B;
		return (info){x,w+B.w};
	}
}f[M][19];
int S,T;
vector<int> p1[N][N],w1[N][N];
int p2[N][N][N],w2[N][N][N];
int B[N][N];
int vis[M][19];
bool check(int x,int y,int z){
	for(int a=1;a<=n;a++) if(a^x&&a^y&&a^z&&above(A[x],A[y],A[a])&&above(A[y],A[z],A[a])&&above(A[z],A[x],A[a])) return 0;
	return 1;
}
info dfs(int msk,int x){
	if(msk==T) return (info){0,1};
	if(x==n) return (info){INF,0};
	if(vis[msk][x]) return f[msk][x];
	int y=x+__builtin_ctz(msk>>x)+1;
	f[msk][x]=dfs(msk,y);
	for(int i=0;i<p1[x][y].size();i++){
		auto w=dfs(msk|(1<<p1[x][y][i]-1),x);
		w.x+=w1[x][y][i];
		f[msk][x]=f[msk][x]+w;
	}
	if(x^1){
		int z=__lg(msk&((1<<x-1)-1))+1;
		if(p2[z][x][y]==1){
			auto w=dfs(msk^(1<<x-1),z);
			w.x+=w2[z][x][y];
			f[msk][x]=f[msk][x]+w;
		}
	}
	vis[msk][x]=1;
	gdb(msk,x,f[msk][x].x);
	return f[msk][x];
}
void Solve(){
	scanf("%d",&n);
	db ap=rnd();
	for(int i=1;i<=n;i++){
		int x,y;scanf("%d%d",&x,&y);
		A[i]=cp(x*cos(ap)+y*sin(ap),y*cos(ap)-x*sin(ap));
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) scanf("%d",&B[i][j]);
	map<db,int> f;
	for(int i=1;i<=n;i++) f[A[i].real()]=i;
	sort(A+1,A+n+1,[](cp x,cp y){return x.real()<y.real();});
	for(int i=1;i<=n;i++) p[i]=f[A[i].real()];
	st[sh=1]=1;
	for(int i=2;i<=n;i++){
		while(sh>1&&!above(A[st[sh-1]],A[st[sh]],A[i])) sh--;
		st[++sh]=i;
	}
	for(int i=1;i<=n;i++) cerr<<A[i].real()<<' '<<A[i].imag()<<'\n';
	S=0,T=0;
	for(int i=1;i<=sh;i++) S|=1ll<<st[i]-1;
	int tot=0;
	for(int i=1;i<sh;i++) tot+=B[p[st[i]]][p[st[i+1]]];
	st[sh=1]=n;
	for(int i=n-1;i;i--){
		while(sh>1&&!above(A[st[sh-1]],A[st[sh]],A[i])) sh--;
		st[++sh]=i;
	}
	for(int i=1;i<=sh;i++) T|=1ll<<st[i]-1;
	gdb(above(A[2],A[4],A[3]));
	for(int x=1;x<=n;x++) for(int y=x+1;y<=n;y++){
		p1[x][y].clear();w1[x][y].clear();
		for(int z=x+1;z<y;z++) if(above(A[x],A[y],A[z])&&check(x,y,z)){
			p1[x][y].push_back(z);
			w1[x][y].push_back(B[p[x]][p[z]]+B[p[z]][p[y]]);
			gdb(x,y,z);
		}
	}
	gdb(S,T);
	for(int x=1;x<=n;x++) for(int y=x+1;y<=n;y++){
		for(int z=y+1;z<=n;z++){
			if(above(A[x],A[y],A[z])){
				if(check(x,y,z)) p2[x][y][z]=1,w2[x][y][z]=B[p[x]][p[z]];
				else p2[x][y][z]=-1;
			}
			else p2[x][y][z]=-1;
		}
	}
	Me(vis,0);
	info w=dfs(S,1);
	w.x+=tot;
	printf("%d %lld\n",w.x,w.w);
}
int main(){
	int t=1;
	scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}