結果
問題 | No.134 走れ!サブロー君 |
ユーザー | dnish |
提出日時 | 2018-06-25 10:03:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,594 bytes |
コンパイル時間 | 1,474 ms |
コンパイル使用メモリ | 168,100 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-09-13 13:50:25 |
合計ジャッジ時間 | 2,405 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,376 KB |
testcase_03 | AC | 1 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,380 KB |
testcase_06 | AC | 3 ms
4,376 KB |
testcase_07 | AC | 4 ms
4,380 KB |
testcase_08 | AC | 6 ms
4,504 KB |
testcase_09 | AC | 5 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 2 ms
4,380 KB |
testcase_13 | AC | 2 ms
4,380 KB |
testcase_14 | AC | 2 ms
4,376 KB |
ソースコード
#include "bits/stdc++.h" #define REP(i,n,N) for(int i=(n); i<(N); i++) #define RREP(i,n,N) for(ll i=(N-1); i>=n; i--) #define CK(n,a,b) ((a)<=(n)&&(n)<(b)) #define ALL(v) (v).begin(),(v).end() #define p(s) cout<<(s)<<endl #define p2(a,b) cout<<(a)<<" "<<(b)<<endl #define v2(T) vector<vector<T>> typedef long long ll; using namespace std; const ll mod=1e9+7; const int inf=1e9; pair<int,int> yx[13]; double W[13]; double dp[1<<13][13]; double cost(int a, int b, double w){ return (abs(yx[a].first-yx[b].first) + abs(yx[a].second-yx[b].second)) * (w+100.0)/120.0 + W[a]; } int main() { int sx,sy,n; cin>>sx>>sy>>n; double sum=0; REP(i,0,n){ int x,y; cin>>x>>y>>W[i]; yx[i] = {y,x}; sum += W[i]; } REP(mask,0,1<<n) REP(i,0,n) dp[mask][i] = inf; dp[0][0] = 0; REP(i,0,n) dp[1<<i][i] = (abs(yx[i].first-sy) + abs(yx[i].second-sx)) * (sum + 100.0)/120.0 + W[i]; REP(mask,1,1<<n){ double sumW=sum; vector<int> ca; REP(i,0,n){ if((mask & (1<<i))){ sumW -= W[i]; ca.push_back(i); } } REP(i,0,n){ if((mask & (1<<i))) continue; for(auto j:ca){ dp[mask | (1<<i)][i] = min(dp[mask|(1<<i)][i], dp[mask][j] + cost(i,j,sumW)); //cout<<i<<" "<<j<<" "<<cost(i,j,sumW)<<endl; } } } double ans=1e9; REP(i,0,n){ ans = min(ans, dp[(1<<n)-1][i] + (abs(yx[i].first-sy) + abs(yx[i].second-sx))* 5.0/6); } printf("%.8lf\n", ans); return 0; }