結果
| 問題 | No.693 square1001 and Permutation 2 |
| コンテスト | |
| ユーザー |
pengin_2000
|
| 提出日時 | 2020-02-20 23:43:53 |
| 言語 | C(gnu17) (gcc 15.2.0) |
| 結果 |
AC
|
| 実行時間 | 0 ms / 2,000 ms |
| + 745µs | |
| コード長 | 424 bytes |
| 記録 | |
| コンパイル時間 | 58 ms |
| コンパイル使用メモリ | 37,888 KB |
| 実行使用メモリ | 5,888 KB |
| 最終ジャッジ日時 | 2026-07-22 16:12:52 |
| 合計ジャッジ時間 | 1,213 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 9 |
ソースコード
#include<stdio.h>
int abs(int n)
{
if (n < 0)
n *= -1;
return n;
}
int main()
{
int n;
scanf("%d", &n);
int i;
int a[55];
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n - 1; i++)
{
if (a[i] > a[i + 1])
{
int b = a[i];
a[i] = a[i + 1];
a[i + 1] = b;
if (i > 0)
i -= 2;
}
}
int ans = 0;
for (i = 0; i < n; i++)
ans += abs(a[i] - i - 1);
printf("%d\n", ans);
return 0;
}
pengin_2000