結果
問題 | No.1607 Kth Maximum Card |
ユーザー | LayCurse |
提出日時 | 2021-07-16 21:33:02 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 388 ms / 3,500 ms |
コード長 | 6,271 bytes |
コンパイル時間 | 2,614 ms |
コンパイル使用メモリ | 224,200 KB |
実行使用メモリ | 19,456 KB |
最終ジャッジ日時 | 2024-07-06 08:29:32 |
合計ジャッジ時間 | 8,478 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 280 ms
19,328 KB |
testcase_09 | AC | 198 ms
16,512 KB |
testcase_10 | AC | 310 ms
19,328 KB |
testcase_11 | AC | 41 ms
7,936 KB |
testcase_12 | AC | 221 ms
16,128 KB |
testcase_13 | AC | 34 ms
6,144 KB |
testcase_14 | AC | 42 ms
7,040 KB |
testcase_15 | AC | 234 ms
15,104 KB |
testcase_16 | AC | 32 ms
6,656 KB |
testcase_17 | AC | 10 ms
5,376 KB |
testcase_18 | AC | 121 ms
11,904 KB |
testcase_19 | AC | 71 ms
9,088 KB |
testcase_20 | AC | 107 ms
9,984 KB |
testcase_21 | AC | 118 ms
10,880 KB |
testcase_22 | AC | 352 ms
19,456 KB |
testcase_23 | AC | 378 ms
19,328 KB |
testcase_24 | AC | 105 ms
9,216 KB |
testcase_25 | AC | 62 ms
7,168 KB |
testcase_26 | AC | 77 ms
7,936 KB |
testcase_27 | AC | 111 ms
9,344 KB |
testcase_28 | AC | 87 ms
8,576 KB |
testcase_29 | AC | 202 ms
13,312 KB |
testcase_30 | AC | 388 ms
18,176 KB |
testcase_31 | AC | 164 ms
12,288 KB |
testcase_32 | AC | 51 ms
10,752 KB |
testcase_33 | AC | 49 ms
10,752 KB |
testcase_34 | AC | 59 ms
10,624 KB |
testcase_35 | AC | 63 ms
10,752 KB |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("inline") #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); } template<class T> inline void walloc1d(T **arr, int x1, int x2, void **mem = &wmem){ walloc1d(arr, x2-x1, mem); (*arr) -= x1; } 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); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ my_putchar_unlocked('-'); } while(s--){ my_putchar_unlocked(f[s]+'0'); } } 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]; } } } ; 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 getDist01(int root, S res[], void *mem = wmem){ int i; int j; int k; int nd; int*q; int qs; int qe; char*don; walloc1d(&q, 2*N, &mem); walloc1d(&don, N, &mem); for(i=(0);i<(N);i++){ res[i] = -1; } for(i=(0);i<(N);i++){ don[i] = 0; } qs = qe = N; q[qe++] = root; res[root] = 0; while(qs < qe){ i = q[qs++]; if(don[i]){ continue; } don[i] = 1; for(j=(0);j<(es[i]);j++){ k = edge[i][j]; nd = res[i] + cost[i][j]; if(res[k]==-1 || res[k] > nd){ res[k] = nd; if(cost[i][j]==0){ q[--qs] = k; } else{ q[qe++] = k; } } } } } int getDist01(int a, int b, void *mem = wmem){ int i; int j; int k; int nd; int*res; int*q; int qs; int qe; char*don; walloc1d(&res, N, &mem); walloc1d(&q, 2*N, &mem); walloc1d(&don, N, &mem); for(i=(0);i<(N);i++){ res[i] = -1; } for(i=(0);i<(N);i++){ don[i] = 0; } qs = qe = N; q[qe++] = a; res[a] = 0; while(qs < qe){ i = q[qs++]; if(i==b){ return res[b]; } if(don[i]){ continue; } don[i] = 1; for(j=(0);j<(es[i]);j++){ k = edge[i][j]; nd = res[i] + cost[i][j]; if(res[k]==-1 || res[k] > nd){ res[k] = nd; if(cost[i][j]==0){ q[--qs] = k; } else{ q[qe++] = k; } } } } return -1; } } ; int N; int M; int K; int A[200000]; int B[200000]; int C[200000]; int d[200000]; wgraph<int> g; int main(){ wmem = memarr; int res; void*mem = wmem; rd(N); rd(M); rd(K); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(M);Lj4PdHRW++){ rd(A[Lj4PdHRW]);A[Lj4PdHRW] += (-1); rd(B[Lj4PdHRW]);B[Lj4PdHRW] += (-1); rd(C[Lj4PdHRW]); } } int e98WHCEY; int cTE1_r3A; int RZTsC2BF; e98WHCEY = 0; cTE1_r3A = 300000; while(e98WHCEY < cTE1_r3A){ int i; if((e98WHCEY + cTE1_r3A)%2==0){ RZTsC2BF = (e98WHCEY + cTE1_r3A) / 2; } else{ RZTsC2BF = (e98WHCEY + cTE1_r3A - 1) / 2; } wmem = mem; for(i=(0);i<(M);i++){ if(C[i] > RZTsC2BF){ d[i] =1; } else{ d[i] =0; } } g.setEdge(N,M,A,B,d); if(g.getDist01(0,N-1) < K){ cTE1_r3A = RZTsC2BF; } else{ e98WHCEY = RZTsC2BF + 1; } } res =cTE1_r3A; wt_L(res); wt_L('\n'); return 0; } // cLay version 20210708-1 // --- original code --- // int N, M, K, A[2d5], B[], C[], d[]; // wgraph<int> g; // { // int res; // void *mem = wmem; // rd(N,M,K,(A--,B--,C)(M)); // res = bsearch_min[int,x,0,3d5][ // wmem = mem; // rep(i,M) d[i] = if[C[i] > x, 1, 0]; // g.setEdge(N,M,A,B,d); // ](g.getDist01(0,N-1) < K); // wt(res); // }