提出 #1563839
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> p(n + 1);
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
}
int result = 0;
for (int i = 1; i <= n; i++) {
if (p[i] == i) {
result++;
if (i < n) swap(p[i], p[i + 1]);
else swap(p[i], p[i - 1]);
}
}
printf("%d\n", result);
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Derangement |
| ユーザ | pauljgblt |
| 言語 | C++14 (GCC 5.4.1) |
| 得点 | 400 |
| コード長 | 406 Byte |
| 結果 | AC |
| 実行時間 | 11 ms |
| メモリ | 640 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:7:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:10:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &p[i]);
^
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt |
| All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 0_000.txt | AC | 1 ms | 256 KiB |
| 0_001.txt | AC | 1 ms | 256 KiB |
| 0_002.txt | AC | 1 ms | 256 KiB |
| 0_003.txt | AC | 1 ms | 256 KiB |
| 1_004.txt | AC | 1 ms | 256 KiB |
| 1_005.txt | AC | 10 ms | 640 KiB |
| 1_006.txt | AC | 10 ms | 640 KiB |
| 1_007.txt | AC | 10 ms | 640 KiB |
| 1_008.txt | AC | 10 ms | 640 KiB |
| 1_009.txt | AC | 10 ms | 640 KiB |
| 1_010.txt | AC | 10 ms | 640 KiB |
| 1_011.txt | AC | 10 ms | 640 KiB |
| 1_012.txt | AC | 10 ms | 640 KiB |
| 1_013.txt | AC | 11 ms | 640 KiB |
| 1_014.txt | AC | 10 ms | 640 KiB |