結果
| 問題 |
No.490 yukiソート
|
| コンテスト | |
| ユーザー |
bal4u
|
| 提出日時 | 2019-05-08 13:34:49 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 870 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 30,208 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-02 00:27:09 |
| 合計ジャッジ時間 | 1,226 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 34 |
コンパイルメッセージ
main.c: In function 'in':
main.c:8:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
8 | #define gc() getchar_unlocked()
| ^~~~~~~~~~~~~~~~
main.c:16:24: note: in expansion of macro 'gc'
16 | int n = 0, c = gc();
| ^~
main.c: In function 'out':
main.c:9:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
9 | #define pc(c) putchar_unlocked(c)
| ^~~~~~~~~~~~~~~~
main.c:26:17: note: in expansion of macro 'pc'
26 | if (!n) pc('0');
| ^~
ソースコード
// yukicoder: No.490 yukiソート
// 2019.5.7 bal4u
#include <stdio.h>
#include <stdlib.h>
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()
{
int n = 0, c = gc();
do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
return n;
}
void out(int n)
{
int i;
char ob[20];
if (!n) pc('0');
else {
i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
while (i--) pc(ob[i]);
}
}
typedef struct { int v, id; } T;
T a[2003];
int cmp(const void *a, const void *b) {
return ((T *)a)->v - ((T *)b)->v;
}
int main()
{
int i, n;
T t;
n = in();
for (i = 0; i < n; i++) a[i].id = i, a[i].v = in();
qsort(a, n, sizeof(T), cmp);
if (a[n-1].id != n-1) t = a[n-1], a[n-1] = a[n-2], a[n-2] = t;
out(a[0].v);
for (i = 1; i < n; i++) pc(' '), out(a[i].v);
pc('\n');
return 0;
}
bal4u