結果
問題 | No.1065 電柱 / Pole (Easy) |
ユーザー | LayCurse |
提出日時 | 2020-05-29 21:35:30 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 126 ms / 2,000 ms |
コード長 | 7,511 bytes |
コンパイル時間 | 2,760 ms |
コンパイル使用メモリ | 216,928 KB |
実行使用メモリ | 27,832 KB |
最終ジャッジ日時 | 2024-11-06 02:44:04 |
合計ジャッジ時間 | 6,107 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
11,980 KB |
testcase_01 | AC | 4 ms
9,932 KB |
testcase_02 | AC | 43 ms
19,660 KB |
testcase_03 | AC | 58 ms
23,500 KB |
testcase_04 | AC | 59 ms
25,740 KB |
testcase_05 | AC | 19 ms
24,348 KB |
testcase_06 | AC | 19 ms
23,372 KB |
testcase_07 | AC | 10 ms
16,768 KB |
testcase_08 | AC | 27 ms
27,832 KB |
testcase_09 | AC | 6 ms
12,428 KB |
testcase_10 | AC | 14 ms
19,276 KB |
testcase_11 | AC | 11 ms
15,888 KB |
testcase_12 | AC | 9 ms
14,640 KB |
testcase_13 | AC | 40 ms
19,280 KB |
testcase_14 | AC | 52 ms
23,168 KB |
testcase_15 | AC | 63 ms
22,580 KB |
testcase_16 | AC | 23 ms
16,340 KB |
testcase_17 | AC | 70 ms
23,372 KB |
testcase_18 | AC | 18 ms
14,968 KB |
testcase_19 | AC | 71 ms
22,384 KB |
testcase_20 | AC | 18 ms
16,204 KB |
testcase_21 | AC | 20 ms
16,884 KB |
testcase_22 | AC | 57 ms
21,580 KB |
testcase_23 | AC | 4 ms
11,876 KB |
testcase_24 | AC | 3 ms
9,840 KB |
testcase_25 | AC | 9 ms
14,688 KB |
testcase_26 | AC | 32 ms
17,836 KB |
testcase_27 | AC | 31 ms
17,860 KB |
testcase_28 | AC | 53 ms
21,708 KB |
testcase_29 | AC | 7 ms
12,608 KB |
testcase_30 | AC | 67 ms
23,396 KB |
testcase_31 | AC | 44 ms
21,008 KB |
testcase_32 | AC | 28 ms
19,168 KB |
testcase_33 | AC | 63 ms
23,520 KB |
testcase_34 | AC | 19 ms
16,732 KB |
testcase_35 | AC | 68 ms
22,300 KB |
testcase_36 | AC | 3 ms
11,976 KB |
testcase_37 | AC | 4 ms
11,980 KB |
testcase_38 | AC | 4 ms
12,000 KB |
testcase_39 | AC | 4 ms
11,852 KB |
testcase_40 | AC | 4 ms
11,852 KB |
testcase_41 | AC | 126 ms
27,784 KB |
testcase_42 | AC | 22 ms
16,600 KB |
testcase_43 | AC | 42 ms
19,532 KB |
testcase_44 | AC | 14 ms
15,160 KB |
testcase_45 | AC | 39 ms
21,308 KB |
testcase_46 | AC | 3 ms
11,844 KB |
testcase_47 | AC | 3 ms
9,932 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; void *wmem; char memarr[96000000]; template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){ static int skip[16] = {0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] ); (*arr)=(T*)(*mem); (*mem)=((*arr)+x); } inline int my_getchar_unlocked(){ static char buf[1048576]; static int s = 1048576; static int e = 1048576; if(s == e && e == 1048576){ e = fread_unlocked(buf, 1, 1048576, stdin); s = 0; } if(s == e){ return EOF; } return buf[s++]; } inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = my_getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = my_getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } struct MY_WRITER{ char buf[1048576]; int s; int e; MY_WRITER(){ s = 0; e = 1048576; } ~MY_WRITER(){ if(s){ fwrite_unlocked(buf, 1, s, stdout); } } } ; MY_WRITER MY_WRITER_VAR; void my_putchar_unlocked(int a){ if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){ fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout); MY_WRITER_VAR.s = 0; } MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a; } inline void wt_L(char a){ my_putchar_unlocked(a); } int WRITER_DOUBLE_DIGIT = 15; inline int writerDigit_double(){ return WRITER_DOUBLE_DIGIT; } inline void writerDigit_double(int d){ WRITER_DOUBLE_DIGIT = d; } inline void wt_L(double x){ const int d = WRITER_DOUBLE_DIGIT; int k; int r; double v; if(x!=x || (x==x+1 && x==2*x)){ my_putchar_unlocked('E'); my_putchar_unlocked('r'); my_putchar_unlocked('r'); return; } if(x < 0){ my_putchar_unlocked('-'); x = -x; } x += 0.5 * pow(0.1, d); r = 0; v = 1; while(x >= 10*v){ v *= 10; r++; } while(r >= 0){ r--; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; v *= 0.1; my_putchar_unlocked(k + '0'); } if(d > 0){ my_putchar_unlocked('.'); v = 1; for(r=(0);r<(d);r++){ v *= 0.1; k = floor(x / v); if(k >= 10){ k = 9; } if(k <= -1){ k = 0; } x -= k * v; my_putchar_unlocked(k + '0'); } } } template<class T> inline T pow2_L(T a){ return a*a; } template <class T> struct DijkstraHeap{ int *hp; int *place; int size; char *visited; T *val; void malloc(int N){ hp = (int*)std::malloc(N*sizeof(int)); place = (int*)std::malloc(N*sizeof(int)); visited = (char*)std::malloc(N*sizeof(char)); val = (T*)std::malloc(N*sizeof(T)); } void free(){ std::free(hp); std::free(place); std::free(visited); std::free(val); } void walloc(int N, void **mem=&wmem){ walloc1d(&hp, N, mem); walloc1d(&place, N, mem); walloc1d(&visited, N, mem); walloc1d(&val, N, mem); } void init(int N){ int i; size = 0; for(i=(0);i<(N);i++){ place[i]=-1; } for(i=(0);i<(N);i++){ visited[i]=0; } } void up(int n){ int m; while(n){ m=(n-1)/2; if(val[hp[m]]<=val[hp[n]]){ break; } swap(hp[m],hp[n]); swap(place[hp[m]],place[hp[n]]); n=m; } } void down(int n){ int m; for(;;){ m=2*n+1; if(m>=size){ break; } if(m+1<size&&val[hp[m]]>val[hp[m+1]]){ m++; } if(val[hp[m]]>=val[hp[n]]){ break; } swap(hp[m],hp[n]); swap(place[hp[m]],place[hp[n]]); n=m; } } void change(int n, T v){ if(visited[n]||(place[n]>=0&&val[n]<=v)){ return; } val[n]=v; if(place[n]==-1){ place[n]=size; hp[size++]=n; up(place[n]); } else{ up(place[n]); } } int pop(void){ int res=hp[0]; place[res]=-1; size--; if(size){ hp[0]=hp[size]; place[hp[0]]=0; down(0); } visited[res]=1; return res; } } ; struct graph{ int N; int *es; int **edge; void setEdge(int N__, int M, int A[], int B[], void **mem = &wmem){ int i; N = N__; walloc1d(&es, N, mem); walloc1d(&edge, N, mem); for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ es[A[i]]++; es[B[i]]++; } for(i=(0);i<(N);i++){ walloc1d(&edge[i], es[i], mem); } for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ edge[A[i]][es[A[i]]++] = B[i]; edge[B[i]][es[B[i]]++] = A[i]; } } void getDist(int root, int res[], void *mem = wmem){ int i; int j; int k; int*q; int s; int z; walloc1d(&q, N, &mem); for(i=(0);i<(N);i++){ res[i]=-1; } res[root]=0; s=0; z=1; q[0]=root; while(z){ i=q[s++]; z--; for(j=(0);j<(es[i]);j++){ k=edge[i][j]; if(res[k]>=0){ continue; } res[k]=res[i]+1; q[s+z++]=k; } } } } ; template<class T> struct wgraph{ int N; int *es; int **edge; T **cost; graph g; void setEdge(int N__, int M, int A[], int B[], T C[], void **mem = &wmem){ int i; N = N__; walloc1d(&es, N, mem); for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ es[A[i]]++; es[B[i]]++; } walloc1d(&edge, N, mem); for(i=(0);i<(N);i++){ walloc1d(&edge[i], es[i], mem); } walloc1d(&cost, N, mem); for(i=(0);i<(N);i++){ walloc1d(&cost[i], es[i], mem); } for(i=(0);i<(N);i++){ es[i] = 0; } for(i=(0);i<(M);i++){ edge[A[i]][es[A[i]]] = B[i]; edge[B[i]][es[B[i]]] = A[i]; cost[A[i]][es[A[i]]++] = C[i]; cost[B[i]][es[B[i]]++] = C[i]; } g.N = N; g.es = es; g.edge = edge; } template<class S> void getDist(int root, S res[], S unreachable = -1, void *mem = wmem){ int i; int j; DijkstraHeap<S> hp; hp.walloc(N, &mem); hp.init(N); hp.change(root,0); while(hp.size){ i = hp.pop(); for(j=(0);j<(es[i]);j++){ hp.change(edge[i][j], hp.val[i]+cost[i][j]); } } for(i=(0);i<(N);i++){ res[i] = (hp.visited[i] ? hp.val[i] : unreachable); } } } ; int N; int M; int S; int T; int X[200000]; int Y[200000]; int A[200000]; int B[200000]; double c[200000]; double dis[200000]; wgraph<double> g; int main(){ int i; wmem = memarr; rd(N); rd(M); rd(S);S += (-1); rd(T);T += (-1); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(X[Lj4PdHRW]); rd(Y[Lj4PdHRW]); } } { int e98WHCEY; for(e98WHCEY=(0);e98WHCEY<(M);e98WHCEY++){ rd(A[e98WHCEY]);A[e98WHCEY] += (-1); rd(B[e98WHCEY]);B[e98WHCEY] += (-1); } } for(i=(0);i<(M);i++){ c[i] = sqrt((pow2_L((X[A[i]]-X[B[i]])))+(pow2_L((Y[A[i]]-Y[B[i]])))); } g.setEdge(N,M,A,B,c); g.getDist(S,dis); wt_L(dis[T]); wt_L('\n'); return 0; } // cLay varsion 20200509-1 // --- original code --- // int N, M, S, T, X[2d5], Y[2d5], A[2d5], B[2d5]; // double c[2d5], dis[2d5]; // wgraph<double> g; // { // rd(N,M,S--,T--,(X,Y)(N),(A--,B--)(M)); // rep(i,M) c[i] = sqrt( (X[A[i]]-X[B[i]])**2 + (Y[A[i]]-Y[B[i]])**2 ); // g.setEdge(N,M,A,B,c); // g.getDist(S,dis); // wt(dis[T]); // }