結果

問題 No.1413 Dynamic Sushi
ユーザー tailstails
提出日時 2021-03-03 17:29:22
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 111 ms / 4,000 ms
コード長 1,656 bytes
コンパイル時間 239 ms
コンパイル使用メモリ 34,872 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-03 06:32:18
合計ジャッジ時間 2,633 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 111 ms
6,820 KB
testcase_02 AC 1 ms
6,816 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 69 ms
6,820 KB
testcase_05 AC 96 ms
6,820 KB
testcase_06 AC 76 ms
6,816 KB
testcase_07 AC 74 ms
6,816 KB
testcase_08 AC 87 ms
6,820 KB
testcase_09 AC 84 ms
6,820 KB
testcase_10 AC 94 ms
6,816 KB
testcase_11 AC 88 ms
6,820 KB
testcase_12 AC 82 ms
6,820 KB
testcase_13 AC 76 ms
6,816 KB
testcase_14 AC 67 ms
6,816 KB
testcase_15 AC 77 ms
6,816 KB
testcase_16 AC 82 ms
6,816 KB
testcase_17 AC 58 ms
6,816 KB
testcase_18 AC 67 ms
6,820 KB
testcase_19 AC 68 ms
6,816 KB
testcase_20 AC 32 ms
6,816 KB
testcase_21 AC 1 ms
6,820 KB
testcase_22 AC 103 ms
6,816 KB
testcase_23 AC 87 ms
6,816 KB
testcase_24 AC 96 ms
6,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'f':
main.c:25:41: warning: implicit declaration of function 'cos' [-Wimplicit-function-declaration]
   25 |                 double jx=s[j].x+s[j].r*cos(ja);
      |                                         ^~~
main.c:1:1: note: include '<math.h>' or provide a declaration of 'cos'
  +++ |+#include <math.h>
    1 | #pragma GCC optimize("Ofast")
main.c:25:41: warning: incompatible implicit declaration of built-in function 'cos' [-Wbuiltin-declaration-mismatch]
   25 |                 double jx=s[j].x+s[j].r*cos(ja);
      |                                         ^~~
main.c:25:41: note: include '<math.h>' or provide a declaration of 'cos'
main.c:26:41: warning: implicit declaration of function 'sin' [-Wimplicit-function-declaration]
   26 |                 double jy=s[j].y+s[j].r*sin(ja);
      |                                         ^~~
main.c:26:41: note: include '<math.h>' or provide a declaration of 'sin'
main.c:26:41: warning: incompatible implicit declaration of built-in function 'sin' [-Wbuiltin-declaration-mismatch]
main.c:26:41: note: include '<math.h>' or provide a declaration of 'sin'
main.c: At top level:
main.c:36:1: warning: return type defaults to 'int' [-Wimplicit-int]
   36 | main(){
      | ^~~~
main.c: In function 'main':
main.c:38:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   38 |         scanf("%d%d",&n,&w);
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>
    1 | #pragma GCC optimize("Ofast")
main.c:38:9: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
   38 |         scanf("%d%d",&n,&w);
      |         ^~~~~
main.c:38:9: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:53:27: warning: implicit declaration of function 'sqrt' [-Wimplicit-function-declaration]
   53 |                 double hi=sqrt(sq(s[j].x)+sq(s[j].y))+s[j].r;
      

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

#define PI 3.14159265358979323846

struct S {
	double x,y,r;
	double v,a;
} s[12];

double limit=2000;
double dp[1<<12][12];

static inline
double sq(double x){
	return x*x;
}

static inline
double f(double ix,double iy,double it,double lo,double hi,int j){
	for(int k=0;k<18;++k){
		double mid=(lo+hi)*.5;
		double jt=it+mid;
		double ja=s[j].a+s[j].v*jt;
		double jx=s[j].x+s[j].r*cos(ja);
		double jy=s[j].y+s[j].r*sin(ja);
		if(sq(jx-ix)+sq(jy-iy)<sq(mid)){
			hi=mid;
		}else{
			lo=mid;
		}
	}
	return it+hi;
}

main(){
	int n,w;
	scanf("%d%d",&n,&w);
	for(int i=0;i<n;++i){
		scanf("%lf%lf%lf%lf%lf",&s[i].x,&s[i].y,&s[i].r,&s[i].v,&s[i].a);
		s[i].x/=w;
		s[i].y/=w;
		s[i].r/=w;
		s[i].v*=PI/180;
		s[i].a*=PI/180;
	}
	for(int m=0;m<1<<n;++m){
		for(int j=0;j<n;++j){
			dp[m][j]=limit;
		}
	}
	for(int j=0;j<n;++j){
		double hi=sqrt(sq(s[j].x)+sq(s[j].y))+s[j].r;
		double lo=hi-s[j].r*2;
		if(lo<0){
			lo=0;
		}
		dp[1<<j][j]=f(0,0,0,lo,hi,j);
	}
	for(int m=0;m<1<<n;++m){
		for(int i=0;i<n;++i){
			if(m&1<<i){
				double it=dp[m][i];
				double ia=s[i].a+s[i].v*it;
				double ix=s[i].x+s[i].r*cos(ia);
				double iy=s[i].y+s[i].r*sin(ia);
				for(int j=0;j<n;++j){
					if(~m&1<<j){
						double hi=sqrt(sq(s[j].x-ix)+sq(s[j].y-iy))+s[j].r;
						double lo=hi-s[j].r*2;
						if(lo<0){
							lo=0;
						}
						if(dp[m|1<<j][j]>it+lo){
							double r=f(ix,iy,it,lo,hi,j);
							if(dp[m|1<<j][j]>r){
								dp[m|1<<j][j]=r;
							}
						}
					}
				}
			}
		}
	}
	double z=limit;
	for(int j=0;j<n;++j){
		double r=dp[(1<<n)-1][j];
		if(z>r){
			z=r;
		}
	}
	printf("%f",z);
}
0