結果

問題 No.693 square1001 and Permutation 2
ユーザー Imperi_NightImperi_Night
提出日時 2018-08-14 02:20:08
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 327 bytes
コンパイル時間 617 ms
コンパイル使用メモリ 48,308 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 16:56:38
合計ジャッジ時間 889 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
main.cpp:13:39: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         for (int i = 0; i<N; i++)scanf("%d", &a[i]);
      |                                  ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
	int N;
	int sum = 0;
	scanf("%d", &N);
	vector <int> a(N);
	for (int i = 0; i<N; i++)scanf("%d", &a[i]);
	sort(a.begin(),a.end());
	for(int i=0;i<N;i++){
	    sum += abs(a[i]-i);
	}
	printf("%d\n", sum);
	return 0;
}
0