Submission #890916


Source Code Expand

#include <bits/stdc++.h>
  
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
 
#define pb emplace_back
#define fi first
#define se second

using namespace std;
 
typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
 
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-8;
const ll MOD = 1e9+7;

template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }
ll in(){ ll x; scanf( "%lld" , &x ); return x; }
 
// head

int n;
int a[100010];

int main(){

  scanf( "%d" , &n );
  REP( i , n ){
    scanf( "%d" , &a[i] ); a[i]--;
  }
    

  int ans = 0;
  REP( i , n ){
    if( a[ a[i] ] == i ) ans++;
  }

  printf( "%d\n" , ans/2 );
  
  return 0;
}

Submission Info

Submission Time
Task B - Friendly Rabbits
User joisino
Language C++14 (GCC 5.4.1)
Score 200
Code Size 1535 Byte
Status AC
Exec Time 12 ms
Memory 640 KB

Compile Error

./Main.cpp: In function ‘ll in()’:
./Main.cpp:43:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 ll in(){ ll x; scanf( "%lld" , &x ); return x; }
                                    ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:52:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf( "%d" , &n );
                     ^
./Main.cpp:54:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf( "%d" , &a[i] ); a[i]--;
                          ^

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 256 KB
0_01.txt AC 3 ms 256 KB
0_02.txt AC 3 ms 256 KB
1_00.txt AC 2 ms 256 KB
1_01.txt AC 12 ms 640 KB
1_02.txt AC 12 ms 640 KB
1_03.txt AC 12 ms 640 KB
1_04.txt AC 12 ms 640 KB
1_05.txt AC 12 ms 640 KB
1_06.txt AC 12 ms 640 KB
1_07.txt AC 12 ms 640 KB
1_08.txt AC 6 ms 384 KB
1_09.txt AC 11 ms 512 KB
1_10.txt AC 9 ms 512 KB
1_11.txt AC 4 ms 256 KB