提出 #73583179
ソースコード 拡げる
#ifndef ONLINE_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
// #include <atcoder/all>
// using namespace atcoder;
using ll = long long; // 2^63-1まで 負の値は可
using ull = unsigned long long; // 0 <= ull <=2^64-1の範囲 負の値は不可
using vl = vector<ll>;
using vvl = vector<vl>;
using P = pair<ll, ll>;
template <typename T>
using MNPQ = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using MXPQ = priority_queue<T, vector<T>, less<T>>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define srep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = s; i > n; i--)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define nall(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define vunique(v) v.erase(unique(nall(v)), v.end())
#define IN(a, x) find(nall(a), x) != a.end()
#define YN(flg) cout << (flg ? "Yes" : "No") << "\n"
#define out_grid(x, y, h, w) !(0 <= x && x < h && 0 <= y && y < w)
#define lmd(...) [&](__VA_ARGS__)
#define debug(x) cerr << #x << " = " << x << endl;
const ll INF = 4e18;
template <typename T>
istream& operator>>(istream& is, vector<T>& a) {
for (auto& x : a) is >> x;
return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T>& a) {
for (int i = 0; i < (int)a.size(); i++) os << a[i] << " ";
return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
os << "{" << p.first << "," << p.second << "}";
return os;
}
template <typename K, typename V>
ostream& operator<<(ostream& os, map<K, V>& a) {
for (auto& [k, v] : a) os << "{key:" << k << ", item:" << v << "} ";
return os;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
vl a(n);
rep(i, n) cin >> a[i];
ll ans = 0;
ll cnt = 0;
rep(i, n) {
if (a[i] == i + 1)
cnt++;
else if (a[a[i] - 1] == i + 1) {
ans++;
}
}
cout << ans / 2 + (cnt * (cnt - 1)) / 2 << endl;
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
E - Min Max Pair |
| ユーザ |
fuguriris |
| 言語 |
C++23 (GCC 15.2.0) |
| 得点 |
300 |
| コード長 |
2197 Byte |
| 結果 |
AC |
| 実行時間 |
17 ms |
| メモリ |
7308 KiB |
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
300 / 300 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
example_00.txt, example_01.txt |
| All |
example_00.txt, example_01.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| example_00.txt |
AC |
1 ms |
3680 KiB |
| example_01.txt |
AC |
1 ms |
3544 KiB |
| test_00.txt |
AC |
16 ms |
6540 KiB |
| test_01.txt |
AC |
4 ms |
4112 KiB |
| test_02.txt |
AC |
13 ms |
5872 KiB |
| test_03.txt |
AC |
11 ms |
5732 KiB |
| test_04.txt |
AC |
5 ms |
4376 KiB |
| test_05.txt |
AC |
10 ms |
5580 KiB |
| test_06.txt |
AC |
17 ms |
7308 KiB |
| test_07.txt |
AC |
17 ms |
7268 KiB |
| test_08.txt |
AC |
16 ms |
7244 KiB |
| test_09.txt |
AC |
1 ms |
3580 KiB |