結果
問題 | No.693 square1001 and Permutation 2 |
ユーザー |
![]() |
提出日時 | 2019-01-14 02:06:19 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 384 bytes |
コンパイル時間 | 562 ms |
コンパイル使用メモリ | 44,092 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 21:47:44 |
合計ジャッジ時間 | 1,169 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%zu", &N); | ~~~~~^~~~~~~~~~~ main.cpp:12:27: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | for (auto& a_i: A) scanf("%d", &a_i); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <cstdio>#include <cstdlib>#include <algorithm>#include <vector>#include <numeric>int main() {size_t N;scanf("%zu", &N);std::vector<int> A(N), B(N);for (auto& a_i: A) scanf("%d", &a_i);std::sort(A.begin(), A.end());std::iota(B.begin(), B.end(), 1);int res = 0;for (size_t i = 0; i < N; ++i)res += abs(A[i]-B[i]);printf("%d\n", res);}