結果
| 問題 | No.178 美しいWhitespace (1) |
| コンテスト | |
| ユーザー |
monburan_0401
|
| 提出日時 | 2018-09-18 16:17:37 |
| 言語 | C11(gcc12 gnu拡張) (gcc 12.4.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 652 bytes |
| 記録 | |
| コンパイル時間 | 114 ms |
| コンパイル使用メモリ | 32,420 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:18:19 |
| 合計ジャッジ時間 | 980 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:18:21: warning: passing argument 4 of ‘qsort’ from incompatible pointer type [-Wincompatible-pointer-types]
18 | qsort(C,N,8,c); // (配列、データ数、1つのメモリ、並び順)
| ^
| |
| int (*)(int *, int *)
In file included from main.c:2:
/usr/include/stdlib.h:971:34: note: expected ‘__compar_fn_t’ {aka ‘int (*)(const void *, const void *)’} but argument is of type ‘int (*)(int *, int *)’
971 | __compar_fn_t __compar) __nonnull ((1, 4));
| ~~~~~~~~~~~~~~^~~~~~~~
main.c:12:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d",&N);
| ^~~~~~~~~~~~~~
main.c:14:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d %d",&a,&b);
| ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <stdlib.h>
int c(int*a,int*b){return*a-*b;} // これを long でも通用するように
int main(void){
int N;
int a,b;
long int C[1000];
long int count = 0;
scanf("%d",&N);
for(int i = 0; i < N; i++){
scanf("%d %d",&a,&b);
C[i] = a + b * 4;
}
qsort(C,N,8,c); // (配列、データ数、1つのメモリ、並び順)
// check ok
/* for(int k = 0; k < N; k++){
printf("%d ",C[k]);
}
printf("\n");
*/
for(int j = 0; j < N-1; j++){
if( (C[j+1] - C[j]) % 2 != 0 ){
printf("-1\n");
return 0;
}else{
count += (C[j+1] - C[j]) / 2 * (j+1);
}
}
printf("%ld\n",count);
return 0;
}
monburan_0401