結果

問題 No.1413 Dynamic Sushi
ユーザー tailstails
提出日時 2021-03-03 16:24:54
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 147 ms / 4,000 ms
コード長 1,370 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 34,672 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-03 05:46:16
合計ジャッジ時間 4,065 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,820 KB
testcase_01 AC 123 ms
6,816 KB
testcase_02 AC 1 ms
6,820 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 128 ms
6,820 KB
testcase_05 AC 132 ms
6,820 KB
testcase_06 AC 137 ms
6,816 KB
testcase_07 AC 138 ms
6,820 KB
testcase_08 AC 133 ms
6,820 KB
testcase_09 AC 144 ms
6,820 KB
testcase_10 AC 135 ms
6,816 KB
testcase_11 AC 137 ms
6,816 KB
testcase_12 AC 142 ms
6,820 KB
testcase_13 AC 143 ms
6,820 KB
testcase_14 AC 145 ms
6,816 KB
testcase_15 AC 144 ms
6,816 KB
testcase_16 AC 142 ms
6,816 KB
testcase_17 AC 145 ms
6,816 KB
testcase_18 AC 147 ms
6,816 KB
testcase_19 AC 140 ms
6,820 KB
testcase_20 AC 61 ms
6,816 KB
testcase_21 AC 2 ms
6,820 KB
testcase_22 AC 137 ms
6,816 KB
testcase_23 AC 141 ms
6,820 KB
testcase_24 AC 140 ms
6,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'f':
main.c:23:20: warning: implicit declaration of function 'sqrt' [-Wimplicit-function-declaration]
   23 |         double hi=(sqrt(sq(s[j].x-ix)+sq(s[j].y-iy))+s[j].r)/w;
      |                    ^~~~
main.c:1:1: note: include '<math.h>' or provide a declaration of 'sqrt'
  +++ |+#include <math.h>
    1 | #pragma GCC optimize("Ofast")
main.c:23:20: warning: incompatible implicit declaration of built-in function 'sqrt' [-Wbuiltin-declaration-mismatch]
   23 |         double hi=(sqrt(sq(s[j].x-ix)+sq(s[j].y-iy))+s[j].r)/w;
      |                    ^~~~
main.c:23:20: note: include '<math.h>' or provide a declaration of 'sqrt'
main.c:28:41: warning: implicit declaration of function 'cos' [-Wimplicit-function-declaration]
   28 |                 double jx=s[j].x+s[j].r*cos(ja);
      |                                         ^~~
main.c:28:41: note: include '<math.h>' or provide a declaration of 'cos'
main.c:28:41: warning: incompatible implicit declaration of built-in function 'cos' [-Wbuiltin-declaration-mismatch]
main.c:28:41: note: include '<math.h>' or provide a declaration of 'cos'
main.c:29:41: warning: implicit declaration of function 'sin' [-Wimplicit-function-declaration]
   29 |                 double jy=s[j].y+s[j].r*sin(ja);
      |                                         ^~~
main.c:29:41: note: include '<math.h>' or provide a declaration of 'sin'
main.c:29:41: warning: incompatible implicit declaration of built-in function 'sin' [-Wbuiltin-declaration-mismatch]
main.c:29:41: note: include '<math.h>' or provide a declaration of 'sin'
main.c: At top level:
main.c:39:1: warning: return type defaults to 'int' [-Wimplicit-int]
   39 | main(){
      | ^~~~
main.c: In function 'main':
main.c:40:9: warning: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
   40 |         scanf("%d%lf",&n,&w);
      |         ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
  +++ |+#include <stdio.h>

ソースコード

diff #

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

#define PI 3.14159265358979323846

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

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,int j){
	double lo=0;
	double hi=(sqrt(sq(s[j].x-ix)+sq(s[j].y-iy))+s[j].r)/w;
	for(int k=0;k<18;++k){
		double mid=(lo+hi)*.5;
		double jt=it+mid;
		double ja=(jt*s[j].v+s[j].a)*(PI/180);
		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*w)){
			hi=mid;
		}else{
			lo=mid;
		}
	}
	return it+hi;
}

main(){
	scanf("%d%lf",&n,&w);
	for(int i=0;i<n;++i){
		scanf("%d%d%d%d%d",&s[i].x,&s[i].y,&s[i].r,&s[i].v,&s[i].a);
	}
	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){
		dp[1<<j][j]=f(0,0,0,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=(it*s[i].v+s[i].a)*(PI/180);
				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 r=f(ix,iy,it,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