QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639316 | #9458. Triangulation | 275307894a | AC ✓ | 89ms | 101664kb | C++14 | 3.7kb | 2024-10-13 18:56:46 | 2024-10-13 18:56:50 |
Judging History
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';
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 24820kb
input:
2 4 0 0 1 1 1 0 0 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0 4 0 0 3 0 1 3 1 1 0 1 1 1 1 0 1 1 1 1 0 1 1 1 1 0
output:
5 2 6 1
result:
ok 2 lines
Test #2:
score: 0
Accepted
time: 89ms
memory: 101664kb
input:
68 3 454 364 117 336 271 84 0 6 2 6 0 10 2 10 0 4 454 364 117 336 271 84 274 296 0 3 2 10 3 0 6 4 2 6 0 5 10 4 5 0 4 603 817 230 695 230 303 604 183 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 454 364 117 336 271 84 274 296 220 225 0 1 7 3 2 1 0 4 4 2 7 4 0 1 5 3 4 1 0 0 2 2 5 0 0 5 666667 788675 333173 78858...
output:
18 1 30 1 0 2 27 1 38 2 35 5 54 1 44 2 18 14 69 1 12 1 88 42 59 1 23 8 180 150 80 1 23 2 0 780 30 12 504 4550 30 4 19656 26888 29 6 26700 168942 24 88 22770 1098904 21 28 30816 7281984 24 27 15327 49789428 24 4 16338 342305320 21 48 42615 2410168190 22 360 44928 17309628327 1240448 1 2613579 1 19532...
result:
ok 68 lines
Extra Test:
score: 0
Extra Test Passed