結果
問題 | No.2604 Initial Motion |
ユーザー | chro_96 |
提出日時 | 2024-01-13 16:12:35 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 679 ms / 3,000 ms |
コード長 | 4,432 bytes |
コンパイル時間 | 465 ms |
コンパイル使用メモリ | 33,676 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-28 01:32:42 |
合計ジャッジ時間 | 14,296 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 1 ms
5,376 KB |
testcase_03 | AC | 22 ms
5,376 KB |
testcase_04 | AC | 26 ms
5,376 KB |
testcase_05 | AC | 22 ms
5,376 KB |
testcase_06 | AC | 23 ms
5,376 KB |
testcase_07 | AC | 22 ms
5,376 KB |
testcase_08 | AC | 22 ms
5,376 KB |
testcase_09 | AC | 21 ms
5,376 KB |
testcase_10 | AC | 23 ms
5,376 KB |
testcase_11 | AC | 23 ms
5,376 KB |
testcase_12 | AC | 24 ms
5,376 KB |
testcase_13 | AC | 615 ms
5,376 KB |
testcase_14 | AC | 439 ms
5,376 KB |
testcase_15 | AC | 267 ms
5,376 KB |
testcase_16 | AC | 606 ms
5,376 KB |
testcase_17 | AC | 679 ms
5,376 KB |
testcase_18 | AC | 660 ms
5,376 KB |
testcase_19 | AC | 652 ms
5,376 KB |
testcase_20 | AC | 580 ms
5,376 KB |
testcase_21 | AC | 471 ms
5,376 KB |
testcase_22 | AC | 651 ms
5,376 KB |
testcase_23 | AC | 480 ms
5,376 KB |
testcase_24 | AC | 594 ms
5,376 KB |
testcase_25 | AC | 628 ms
5,376 KB |
testcase_26 | AC | 508 ms
5,376 KB |
testcase_27 | AC | 440 ms
5,376 KB |
testcase_28 | AC | 472 ms
5,376 KB |
testcase_29 | AC | 599 ms
5,376 KB |
testcase_30 | AC | 445 ms
5,376 KB |
testcase_31 | AC | 524 ms
5,376 KB |
testcase_32 | AC | 426 ms
5,376 KB |
testcase_33 | AC | 248 ms
5,376 KB |
testcase_34 | AC | 183 ms
5,376 KB |
testcase_35 | AC | 231 ms
5,376 KB |
testcase_36 | AC | 375 ms
5,376 KB |
testcase_37 | AC | 83 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 216 ms
5,376 KB |
testcase_41 | AC | 209 ms
5,376 KB |
ソースコード
#include <stdio.h> #define INF 2000000000000001LL typedef struct list { int v; int c; long long d; struct list *n; struct list *rev; } list; void upheap (long long q[][2], int idx) { int pidx = (idx-1)/2; if (idx > 0 && q[pidx][0] > q[idx][0]) { long long s = q[idx][0]; q[idx][0] = q[pidx][0]; q[pidx][0] = s; s = q[idx][1]; q[idx][1] = q[pidx][1]; q[pidx][1] = s; upheap(q, pidx); } return; } void downheap (long long q[][2], int idx, int size) { int chidx = -1; long long ch[2] = { INF, INF }; if (2*idx+1 >= size) { return; } ch[0] = q[2*idx+1][0]; if (2*idx+2 < size) { ch[1] = q[2*idx+2][0]; } if (ch[1] < ch[0] && ch[1] < q[idx][0]) { chidx = 2*idx+2; } else if (ch[0] < q[idx][0]) { chidx = 2*idx+1; } if (chidx > 0) { long long s = q[idx][0]; q[idx][0] = q[chidx][0]; q[chidx][0] = s; s = q[idx][1]; q[idx][1] = q[chidx][1]; q[chidx][1] = s; downheap(q, chidx, size); } return; } void dequeue (long long q[][2], int *size, long long *res) { res[0] = q[0][0]; res[1] = q[0][1]; if (*size > 0) { *size -= 1; q[0][0] = q[*size][0]; q[0][1] = q[*size][1]; downheap(q, 0, *size); } return; } int main () { int k = 0; int n = 0; int m = 0; int a = 0; int b[2000] = {}; int u = 0; int v = 0; long long d = 0LL; int res = 0; long long ans = 0LL; long long ad[2002] = {}; long long td[2002] = {}; int cnt[2000] = {}; list pool[16000] = {}; int used = 0; list *e[2002] = {}; list *prev[2002] = {}; long long q[16000][2] = {}; res = scanf("%d", &k); res = scanf("%d", &n); res = scanf("%d", &m); for (int i = 0; i < k; i++) { res = scanf("%d", &a); cnt[a-1]++; } for (int i = 0; i < n; i++) { res = scanf("%d", b+i); } for (int i = 0; i < m; i++) { res = scanf("%d", &u); res = scanf("%d", &v); res = scanf("%lld", &d); pool[used].v = v; pool[used].c = k; pool[used].d = d; pool[used].n = e[u]; pool[used].rev = pool+(used+1); e[u] = pool+used; used++; pool[used].v = u; pool[used].c = 0; pool[used].d = d*(-1LL); pool[used].n = e[v]; pool[used].rev = pool+(used-1); e[v] = pool+used; used++; pool[used].v = u; pool[used].c = k; pool[used].d = d; pool[used].n = e[v]; pool[used].rev = pool+(used+1); e[v] = pool+used; used++; pool[used].v = v; pool[used].c = 0; pool[used].d = d*(-1LL); pool[used].n = e[u]; pool[used].rev = pool+(used-1); e[u] = pool+used; used++; } for (int i = 0; i < n; i++) { pool[used].v = i+1; pool[used].c = cnt[i]; pool[used].d = 0LL; pool[used].n = e[0]; pool[used].rev = pool+(used+1); e[0] = pool+used; used++; pool[used].v = 0; pool[used].c = 0; pool[used].d = 0LL; pool[used].n = e[i+1]; pool[used].rev = pool+(used-1); e[i+1] = pool+used; used++; pool[used].v = n+1; pool[used].c = b[i]; pool[used].d = 0LL; pool[used].n = e[i+1]; pool[used].rev = pool+(used+1); e[i+1] = pool+used; used++; pool[used].v = i+1; pool[used].c = 0; pool[used].d = 0LL; pool[used].n = e[n+1]; pool[used].rev = pool+(used-1); e[n+1] = pool+used; used++; } while (k > 0) { int qsize = 0; int idx = n+1; for (int i = 0; i < n+2; i++) { td[i] = INF; } td[0] = 0LL; q[qsize][0] = 0LL; q[qsize][1] = 0LL; upheap(q, qsize); qsize++; while (qsize > 0) { long long tmp[2] = {}; dequeue(q, &qsize, tmp); if (tmp[0] == td[(int)(tmp[1])]) { list *l = e[(int)(tmp[1])]; while (l != NULL) { if (l->c > 0 && td[l->v] > tmp[0]+l->d) { td[l->v] = tmp[0]+l->d; prev[l->v] = l; q[qsize][0] = td[l->v]; q[qsize][1] = (long long)(l->v); upheap(q, qsize); qsize++; } l = l->n; } } } while (idx > 0) { list *l = prev[idx]; l->c--; l->rev->c++; idx = l->rev->v; } for (int i = 0; i < n+2; i++) { list *l = e[i]; ad[i] += td[i]; while (l != NULL) { l->d += td[i]-td[l->v]; l = l->n; } } ans += ad[n+1]; k--; } printf("%lld\n", ans); return 0; }