Submission #892095


Source Code Expand

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n; cin >> n;
    int a[100010]; rep(i,0,n) {cin >> a[i]; a[i]--; }
    bool check[100010];
    memset(check, false, sizeof(check));

    int ans = 0;
    rep(i,0,n) {
        if(check[i]) continue;
        if(a[a[i]] == i) {
            check[i] = true;
            check[a[i]] = true;
            ans++;
        }
        else check[i] = true;
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Friendly Rabbits
User tsutaj
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1693 Byte
Status AC
Exec Time 35 ms
Memory 768 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 3
AC × 15
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt
Case Name Status Exec Time Memory
0_00.txt AC 2 ms 384 KB
0_01.txt AC 2 ms 384 KB
0_02.txt AC 2 ms 384 KB
1_00.txt AC 2 ms 384 KB
1_01.txt AC 35 ms 768 KB
1_02.txt AC 34 ms 768 KB
1_03.txt AC 34 ms 768 KB
1_04.txt AC 35 ms 768 KB
1_05.txt AC 35 ms 768 KB
1_06.txt AC 34 ms 768 KB
1_07.txt AC 35 ms 768 KB
1_08.txt AC 14 ms 512 KB
1_09.txt AC 29 ms 640 KB
1_10.txt AC 24 ms 640 KB
1_11.txt AC 7 ms 384 KB