Please sign in first.
Submission #23594972
Source Code Expand
/*
As soon as man understands that it is only the Qualities which act
and nothing else, and perceives that which is beyond,
he attains My divine nature.
When the soul transcends the Qualities,
which are the real cause of physical existence,
then, freed from birth and death,
from old age and misery, he quaffs the nectar of
Immortality.
-- "SHRI BHAGVAT GITA"
-----------------------------------------------------------------------
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define popb pop_back
#define mp make_pair
#define ve vector
#define vii vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define pll pair < ll , ll >
#define vpl vector < pll >
#define fi first
#define sz size
#define len length
#define se second
//const ll mod=998244353;
const ll mod = 1000000000+7;
const ll N=10000000+6;
const ll INFF=1000000000000000000;
#define M_PI 3.14159265358979323846
//--------------------------------------------
//------------------------------------
vii parent(300000);
vii sized(300000);
void make()
{
for(int i = 0; i <= 299999; i++)
parent[i] = i , sized[i] = 1;
}
//-------------------------------------------
int find(int a)
{
if(a == parent[a]) return a;
return parent[a] = find(parent[a]);
}
void merge(int a , int b)
{
a = find(a) ; b = find(b);
if(a != b)
{
parent[b] = a;
sized[a] += sized[b];
}
}
//============================================
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen ("INPUT.txt" , "r" , stdin);
freopen ("OUTPUT.txt", "w" , stdout);
#endif
int n;
cin >> n;
make();
int arr[n];
for(int i = 0; i < n; i++) cin >> arr[i];
int l = 0 , r = n-1;
while(l < r){
if(arr[l] == arr[r]) {
l++;r--;
}
else
{
merge(arr[l] , arr[r]);
l++, r--;
}
}
ll ans = 0;
vii vis(250030);
for(int i = 1; i <= 250000; i++)
{
int g = find(i);
if(!vis[g])
{
vis[g] = 1;
ans = ans + sized[g] - 1;
}
}
cout << ans;
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | D - KAIBUNsyo |
| User | sr4saurabh |
| Language | C++ (GCC 9.2.1) |
| Score | 400 |
| Code Size | 2696 Byte |
| Status | AC |
| Exec Time | 35 ms |
| Memory | 9012 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01.txt, sample_02.txt, sample_03.txt |
| All | sample_01.txt, sample_02.txt, sample_03.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, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| sample_01.txt | AC | 12 ms | 6544 KiB |
| sample_02.txt | AC | 9 ms | 6620 KiB |
| sample_03.txt | AC | 7 ms | 6488 KiB |
| test_01.txt | AC | 10 ms | 6600 KiB |
| test_02.txt | AC | 8 ms | 6516 KiB |
| test_03.txt | AC | 8 ms | 6580 KiB |
| test_04.txt | AC | 10 ms | 6632 KiB |
| test_05.txt | AC | 8 ms | 6604 KiB |
| test_06.txt | AC | 10 ms | 6532 KiB |
| test_07.txt | AC | 29 ms | 7164 KiB |
| test_08.txt | AC | 32 ms | 7400 KiB |
| test_09.txt | AC | 13 ms | 6636 KiB |
| test_10.txt | AC | 24 ms | 7060 KiB |
| test_11.txt | AC | 16 ms | 6808 KiB |
| test_12.txt | AC | 8 ms | 6636 KiB |
| test_13.txt | AC | 22 ms | 6848 KiB |
| test_14.txt | AC | 22 ms | 6844 KiB |
| test_15.txt | AC | 23 ms | 7336 KiB |
| test_16.txt | AC | 35 ms | 7332 KiB |
| test_17.txt | AC | 26 ms | 7260 KiB |
| test_18.txt | AC | 32 ms | 7372 KiB |
| test_19.txt | AC | 28 ms | 7400 KiB |
| test_20.txt | AC | 34 ms | 7424 KiB |
| test_21.txt | AC | 33 ms | 7388 KiB |
| test_22.txt | AC | 34 ms | 7272 KiB |
| test_23.txt | AC | 24 ms | 7364 KiB |
| test_24.txt | AC | 23 ms | 9012 KiB |
| test_25.txt | AC | 23 ms | 7332 KiB |
| test_26.txt | AC | 23 ms | 7428 KiB |
| test_27.txt | AC | 25 ms | 7360 KiB |
| test_28.txt | AC | 32 ms | 7252 KiB |