結果
問題 | No.14 最小公倍数ソート |
ユーザー | ゆるく |
提出日時 | 2015-01-28 01:32:21 |
言語 | C90 (gcc 11.4.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,410 bytes |
コンパイル時間 | 424 ms |
コンパイル使用メモリ | 24,576 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-23 03:31:00 |
合計ジャッジ時間 | 49,662 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
コンパイルメッセージ
main.c: In function ‘main’: main.c:37:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%d", &n); | ^~~~~~~~~~~~~~~ main.c:40:13: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 40 | rep(i, n) scanf("%d", &b[i]); | ^~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <math.h> #include <limits.h> #include <stdlib.h> typedef long long ll; #define MAX_N 112233 #define REP(i, x, n) for(i = x; i < n; i++) #define rep(i,n) REP(i,0,n) #define INF 0x7FFFFFFF #define ALLOCA(type, n) ((type*)alloca(sizeof(type) * (n))) #define MALLOC(type, n) ((type*)malloc(sizeof(type) * (n))) #define CALLOC(type, n) ((type*)calloc((n), sizeof(type))) #define REALLOC(type, n, p) ((type*)realloc((p), sizeof(type) * (n))) typedef struct heap_queue{long *data;long size;}hq; void heappush(hq *q,int data){long i = q->size;q->size++;while(i > 0){long p = (i - 1) / 2;if (q->data[p]<=data){break;}q->data[i] = q->data[p];i=p;}q->data[i] = data;} long heappop(hq *q){long ret = q->data[0];q->size--;long data = q->data[q->size];long i = 0;while(i * 2 + 1 < q->size) {long a = i * 2 + 1, b = i * 2 + 2;if (b < q->size && q->data[b] < q->data[a]) {a=b;}if (q->data[a] >= data) {break;}q->data[i] = q->data[a];i=a;}q->data[i]=data;return ret;} #define SORT(h, n) qsort(h, n, sizeof(h[0]), ASC) #define RSORT(h, n) qsort(h, n, sizeof(h[0]), DESC) int ASC(const void *c1,const void *c2){int tmp1=*(int *)c1;int tmp2=*(int *)c2;if(tmp1<tmp2){return -1;}if(tmp1==tmp2){return 0;}if(tmp1>tmp2){return 1;}} int DESC(const void *c1,const void *c2){int tmp1 = *(int *)c1;int tmp2=*(int *)c2;if(tmp1>tmp2){return -1;}if(tmp1==tmp2){return 0;}if(tmp1<tmp2){return 1;}} int Gcd(int m, int n){return (n <= 0) ? m:Gcd(n, m % n);} int Bcd(int m, int n){return m * n / Gcd(m, n);} int main(void) { int i,j,k; int *b; int *ans; int n; int index = 0; int data[3] = {INF,INF,INF}; int tmp = 0; scanf("%d", &n); b = MALLOC(int, n + 1); ans = CALLOC(int, n + 1); rep(i, n) scanf("%d", &b[i]); ans[0] = b[0]; while(n > index) { data[0] = INF; data[1] = INF; data[2] = INF; REP(j, 1, n) { if(b[j] != 0) { tmp = Bcd(ans[index], b[j]); if (tmp == data[2]) { if (b[j] < data[0]) { data[0] = b[j]; data[1] = j; data[2] = tmp; } } else { if(tmp < data[2]) { data[0] = b[j]; data[1] = j; data[2] = tmp; } } } } index++; if (n <= index) break; ans[index] = data[0]; b[data[1]] = 0; } rep(k, n) printf("%d ", ans[k]); puts("\n"); free(b); free(ans); return 0; }