結果

問題 No.2938 Sigma Sigma Distance Distance Problem
ユーザー Maeda
提出日時 2025-03-27 11:38:05
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 580 bytes
コンパイル時間 892 ms
コンパイル使用メモリ 25,984 KB
実行使用メモリ 9,116 KB
最終ジャッジ日時 2025-03-27 11:38:10
合計ジャッジ時間 5,080 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:24:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]
   24 |     printf("%d",result);
      |             ~^  ~~~~~~
      |              |  |
      |              |  long int
      |              int
      |             %ld
main.c:4:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 |     scanf("%d",&n);
      |     ^~~~~~~~~~~~~~
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d",&numList[i]);
      |         ^~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
void main(void){
    int n = 0 ;
    scanf("%d",&n);
    int numList[n] = {};
    for(int i = 0 ; i < n ; i++ ){
        scanf("%d",&numList[i]);
    }
    long int result = 0 ;  
    for(int i = 0 ; i < n ; i++ ){
        for(int j= 0 ; j < n ; j++ ){
             double ansA = i - j;
            if(ansA > 0 ){
               ansA *= -1;
            }
        
            double ansB = numList[i] - numList[j];
            if(ansB> 0 ){
               ansB *= -1;
            } 
            result += ansA*ansB;
        }
    }
    printf("%d",result);
}   
0