結果

問題 No.1413 Dynamic Sushi
ユーザー tailstails
提出日時 2021-03-03 16:22:28
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 148 ms / 4,000 ms
コード長 1,364 bytes
コンパイル時間 1,291 ms
コンパイル使用メモリ 35,604 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 08:39:09
合計ジャッジ時間 5,150 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 127 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 130 ms
6,944 KB
testcase_05 AC 134 ms
6,944 KB
testcase_06 AC 140 ms
6,944 KB
testcase_07 AC 141 ms
6,940 KB
testcase_08 AC 136 ms
6,944 KB
testcase_09 AC 145 ms
6,944 KB
testcase_10 AC 137 ms
6,940 KB
testcase_11 AC 139 ms
6,944 KB
testcase_12 AC 144 ms
6,940 KB
testcase_13 AC 146 ms
6,944 KB
testcase_14 AC 146 ms
6,944 KB
testcase_15 AC 146 ms
6,940 KB
testcase_16 AC 143 ms
6,940 KB
testcase_17 AC 145 ms
6,940 KB
testcase_18 AC 148 ms
6,940 KB
testcase_19 AC 141 ms
6,944 KB
testcase_20 AC 61 ms
6,944 KB
testcase_21 AC 1 ms
6,944 KB
testcase_22 AC 138 ms
6,940 KB
testcase_23 AC 144 ms
6,944 KB
testcase_24 AC 142 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'f':
main.c:23:20: warning: implicit declaration of function 'sqrt' [-Wimplicit-function-declaration]
   23 |         double hi=(sqrt(sq(js.x-ix)+sq(js.y-iy))+js.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(js.x-ix)+sq(js.y-iy))+js.r)/w;
      |                    ^~~~
main.c:23:20: note: include '<math.h>' or provide a declaration of 'sqrt'
main.c:28:37: warning: implicit declaration of function 'cos' [-Wimplicit-function-declaration]
   28 |                 double jx=js.x+js.r*cos(ja);
      |                                     ^~~
main.c:28:37: note: include '<math.h>' or provide a declaration of 'cos'
main.c:28:37: warning: incompatible implicit declaration of built-in function 'cos' [-Wbuiltin-declaration-mismatch]
main.c:28:37: note: include '<math.h>' or provide a declaration of 'cos'
main.c:29:37: warning: implicit declaration of function 'sin' [-Wimplicit-function-declaration]
   29 |                 double jy=js.y+js.r*sin(ja);
      |                                     ^~~
main.c:29:37: note: include '<math.h>' or provide a declaration of 'sin'
main.c:29:37: warning: incompatible implicit declaration of built-in function 'sin' [-Wbuiltin-declaration-mismatch]
main.c:29:37: 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>
    1 | #pragma GCC optimize

ソースコード

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