Submission #891398


Source Code Expand

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i, n) {
        cin >> a[i];
        a[i]--;
    }

    vector<bool> b(n,false);
    int ans=0;
    REP(i,n){
        if (a[a[i]]==i && b[i] ==false && b[a[i]]==false){
            b[i] =true;
            b[a[i]]=true;
            ans++;
        }
    }

    cout << ans << ENDL;

    return 0;
}

Submission Info

Submission Time
Task B - Friendly Rabbits
User NSTomoS
Language C++11 (GCC 4.8.1)
Score 200
Code Size 1664 Byte
Status AC
Exec Time 12 ms
Memory 1024 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 3 ms 256 KB
0_01.txt AC 3 ms 384 KB
0_02.txt AC 3 ms 256 KB
1_00.txt AC 3 ms 256 KB
1_01.txt AC 12 ms 1024 KB
1_02.txt AC 12 ms 1024 KB
1_03.txt AC 12 ms 1024 KB
1_04.txt AC 12 ms 1024 KB
1_05.txt AC 12 ms 1024 KB
1_06.txt AC 12 ms 1024 KB
1_07.txt AC 12 ms 1024 KB
1_08.txt AC 6 ms 512 KB
1_09.txt AC 10 ms 896 KB
1_10.txt AC 9 ms 768 KB
1_11.txt AC 4 ms 384 KB