結果
問題 | No.19 ステージの選択 |
ユーザー | mudbdb |
提出日時 | 2015-07-14 22:36:16 |
言語 | C90 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 2,239 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 23,808 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-02 12:29:15 |
合計ジャッジ時間 | 930 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 1 ms
6,944 KB |
testcase_02 | AC | 0 ms
6,940 KB |
testcase_03 | AC | 0 ms
6,940 KB |
testcase_04 | AC | 0 ms
6,940 KB |
testcase_05 | AC | 0 ms
6,940 KB |
testcase_06 | AC | 1 ms
6,944 KB |
testcase_07 | AC | 0 ms
6,940 KB |
testcase_08 | AC | 1 ms
6,948 KB |
testcase_09 | AC | 0 ms
6,940 KB |
testcase_10 | AC | 1 ms
6,944 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 0 ms
6,940 KB |
testcase_14 | AC | 0 ms
6,944 KB |
testcase_15 | AC | 1 ms
6,940 KB |
testcase_16 | AC | 1 ms
6,948 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,944 KB |
testcase_19 | AC | 0 ms
6,940 KB |
testcase_20 | AC | 1 ms
6,944 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 1 ms
6,940 KB |
testcase_23 | AC | 1 ms
6,940 KB |
コンパイルメッセージ
main.c: In function ‘main’: main.c:18:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | scanf("%d", &N); | ^~~~~~~~~~~~~~~ main.c:23:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%d", &(L[i])); | ^~~~~~~~~~~~~~~~~~~~ main.c:24:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d", &(S[i])); | ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <stdlib.h> struct cycle { struct cycle *next; int nu; int *mem; }; struct cycle *Root = 0; int cmp(const void* a, const void* b) { return (*(int*)a - *(int*)b); } int main() { int N; int *L; int *S; scanf("%d", &N); L = (int*)malloc(sizeof(int)*N); S = (int*)malloc(sizeof(int)*N); int i; for (i=0; i<N; i++) { scanf("%d", &(L[i])); scanf("%d", &(S[i])); } int *path = (int*)malloc(sizeof(int)*N); int path_i = 0; int *work = (int*)malloc(sizeof(int)*N); int work_i = 0; int *v = (int*)malloc(sizeof(int)*N); for (i=0; i<N; i++) v[i] = 0; int no; int up; int j; struct cycle *p; for (no=1; no<=N; no++) { if (v[no-1] == 0) { v[no-1] = 1; path_i = 0; path[path_i] = no; path_i++; up = S[no-1]; while (1) { if (path_i > N) { printf("!?\n"); exit(1); } for (i=path_i-1; i>=0; i--) { if (up == path[i]) { work_i = path_i - i; for (j=0; j<work_i; j++) work[j] = path[j+i]; qsort(work, work_i, sizeof(int), cmp); for (p=Root; p!=0; p=p->next) { if (p->mem[0] == work[0]) { goto SKIP; } } p = (struct cycle*)malloc(sizeof(struct cycle)); p->next = Root; Root = p; p->nu = work_i; p->mem = (int*)malloc(sizeof(int)*p->nu); for (j=0; j<p->nu; j++) p->mem[j] = work[j]; goto SKIP; } } path[path_i] = up; path_i++; v[up-1] = 1; up = S[up-1]; } SKIP: ; } } int *ldwn = (int*)malloc(sizeof(int)*N); for (i=0; i<N; i++) ldwn[i] = 1; int min; int min_i; for (p=Root; p!=0; p=p->next) { min = ~(1 << 31); for (i=0; i<p->nu; i++) { if (L[p->mem[i]-1] < min) { min = L[p->mem[i]-1]; min_i = p->mem[i]-1; } } ldwn[min_i] = 0; } float total = 0; for (i=0; i<N; i++) { if (ldwn[i] == 1) { total += L[i]; } } total /= 2; for (i=0; i<N; i++) { if (ldwn[i] == 0) { total += L[i]; } } printf("%.1f\n", total); return 0; }