提出 #4635386
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
using VS = vector<string>; using LL = long long;
using VI = vector<int>; using VVI = vector<VI>;
using PII = pair<int, int>; using PLL = pair<LL, LL>;
using VL = vector<LL>; using VVL = vector<VL>;
#define ALL(a) begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3")
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x)
#endif
const int INF = 1e9; const LL LINF = 1e16;
const LL MOD = 1000000007; const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 }; int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };
/* ----- __MAKE_TIME__ Problem: __PROBLEM__ / Link: __CONTEST_URL__ ----- */
/* ------問題------
-----問題ここまで----- */
/* -----解説等-----
----解説ここまで---- */
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
LL N; cin >> N;
VL a(N);
FOR(i, 0, N) {
cin >> a[i];
}
auto f = [](const VL& a) {
LL ret = 0;
FOR(i, 0, SZ(a)) {
if (a[i] == i + 1)ret++,i++;
}
return ret;
};
auto g = [](const VL& a) {
LL ret = 0;
FORR(i, SZ(a) - 1, 0 - 1) {
if (a[i] == i + 1)ret++,i--;
}
return ret;
};
LL ans = min(f(a), g(a));
cout << ans << endl;
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
D - Derangement |
| ユーザ |
Yang33 |
| 言語 |
C++14 (GCC 5.4.1) |
| 得点 |
400 |
| コード長 |
1634 Byte |
| 結果 |
AC |
| 実行時間 |
9 ms |
| メモリ |
1024 KiB |
ジャッジ結果
| セット名 |
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 |
9 ms |
1024 KiB |
| 1_006.txt |
AC |
9 ms |
1024 KiB |
| 1_007.txt |
AC |
9 ms |
1024 KiB |
| 1_008.txt |
AC |
9 ms |
1024 KiB |
| 1_009.txt |
AC |
9 ms |
1024 KiB |
| 1_010.txt |
AC |
9 ms |
1024 KiB |
| 1_011.txt |
AC |
9 ms |
1024 KiB |
| 1_012.txt |
AC |
9 ms |
1024 KiB |
| 1_013.txt |
AC |
9 ms |
1024 KiB |
| 1_014.txt |
AC |
9 ms |
1024 KiB |