結果

問題 No.693 square1001 and Permutation 2
ユーザー toto
提出日時 2025-03-28 11:59:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 478 bytes
コンパイル時間 256 ms
コンパイル使用メモリ 28,160 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-28 11:59:32
合計ジャッジ時間 1,100 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 4
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d",&val);
      |         ~~~~~^~~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |                 scanf("%d",&arr[i]);
      |                 ~~~~~^~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	// 配列の要素数
	int val = 0;
	scanf("%d",&val);
	// 配列の要素
	int arr[val];
	for(int i = 0;i < val;i ++){
		scanf("%d",&arr[i]);
	}
	
	// ソート
	for(int i = 0;i < val;i ++){
		for(int j = 0;j < val; j ++){
			if(arr[i] < arr[j]){
				int tmp = arr[i];
				arr[i] = arr[j];
				arr[j] = tmp;
			}
		}
	}
	
	int cost = 0;
	for(int i = 0;i < val;i ++){
		while(arr[i] < i + 1){
			arr[i]++;
			cost++;
		}
	}
	printf("%d",cost);
}
0