Submission #1388409
Source Code Expand
#include <bits/stdc++.h> // #include "stdafx.h" // #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS using namespace std; #define gc getchar_unlocked #define fo(i,n) for(i=0;i<n;i++) #define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1) #define ll long long #define si(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define ss(s) scanf("%s",s) #define pi(x) printf("%d\n",x) #define pl(x) printf("%lld\n",x) #define ps(s) printf("%s\n",s) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(), x.end() #define clr(x) memset(x, 0, sizeof(x)) #define sortall(x) sort(all(x)) #define tr(it, a) for(auto it = a.begin(); it != a.end(); it++) #define PI 3.1415926535897932384626 typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; int mpow(int base, int exp); void ipgraph(int m); int dfs(int u); const int mod = 1000000007; const int N = 3e5, M = N; //======================= map<int, vi> g; int a[N]; int b[N]; map<int,int> vis; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int i,n,k,j; cin >> n; int x = 0; multiset<int> A; fo(i, n) cin >> a[i+1], x ^= a[i+1], A.insert(a[i+1]); a[0] = x; A.insert(x); fo(i, n) { cin >> b[i+1]; if(A.find(b[i+1]) == A.end()){ cout << -1 << endl; return 0; } A.erase(A.find(b[i+1])); } b[0] = *A.begin(); fo(i, n+1){ g[b[i]].pb(a[i]); } int ans = max(1,dfs(a[0])) - 1; if(a[0] == b[0] and ans) ans++; Fo(i, 1, n+1) { if(!vis[a[i]]){ x = dfs(a[i]); if(x) ans += x+1; } } cout << ans << endl; return 0; } int dfs(int u){ vis[u] = 1; int ans = 0; for(int v:g[u]){ if(v == u) continue; ans++; if (vis[v]) continue; ans += dfs(v); } return ans; }
Submission Info
Submission Time | |
---|---|
Task | D - XOR Replace |
User | rachitjain |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 2072 Byte |
Status | AC |
Exec Time | 293 ms |
Memory | 26112 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.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, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt, 1_64.txt, 1_65.txt, 1_66.txt, 1_67.txt, 1_68.txt, 1_69.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 2 ms | 384 KB |
0_01.txt | AC | 1 ms | 256 KB |
0_02.txt | AC | 1 ms | 256 KB |
0_03.txt | AC | 1 ms | 256 KB |
1_00.txt | AC | 1 ms | 256 KB |
1_01.txt | AC | 1 ms | 256 KB |
1_02.txt | AC | 1 ms | 256 KB |
1_03.txt | AC | 1 ms | 256 KB |
1_04.txt | AC | 1 ms | 256 KB |
1_05.txt | AC | 1 ms | 256 KB |
1_06.txt | AC | 1 ms | 256 KB |
1_07.txt | AC | 113 ms | 16640 KB |
1_08.txt | AC | 130 ms | 26112 KB |
1_09.txt | AC | 124 ms | 16640 KB |
1_10.txt | AC | 45 ms | 5632 KB |
1_11.txt | AC | 43 ms | 5632 KB |
1_12.txt | AC | 44 ms | 5504 KB |
1_13.txt | AC | 45 ms | 5760 KB |
1_14.txt | AC | 58 ms | 5632 KB |
1_15.txt | AC | 52 ms | 5760 KB |
1_16.txt | AC | 58 ms | 5760 KB |
1_17.txt | AC | 52 ms | 5760 KB |
1_18.txt | AC | 73 ms | 5632 KB |
1_19.txt | AC | 63 ms | 5632 KB |
1_20.txt | AC | 71 ms | 5632 KB |
1_21.txt | AC | 63 ms | 5760 KB |
1_22.txt | AC | 91 ms | 5760 KB |
1_23.txt | AC | 77 ms | 5760 KB |
1_24.txt | AC | 91 ms | 5760 KB |
1_25.txt | AC | 77 ms | 5760 KB |
1_26.txt | AC | 110 ms | 5760 KB |
1_27.txt | AC | 95 ms | 5632 KB |
1_28.txt | AC | 112 ms | 5888 KB |
1_29.txt | AC | 94 ms | 5760 KB |
1_30.txt | AC | 124 ms | 5888 KB |
1_31.txt | AC | 94 ms | 5632 KB |
1_32.txt | AC | 126 ms | 6016 KB |
1_33.txt | AC | 96 ms | 5760 KB |
1_34.txt | AC | 141 ms | 6272 KB |
1_35.txt | AC | 93 ms | 5632 KB |
1_36.txt | AC | 138 ms | 6272 KB |
1_37.txt | AC | 92 ms | 5632 KB |
1_38.txt | AC | 172 ms | 7808 KB |
1_39.txt | AC | 74 ms | 5504 KB |
1_40.txt | AC | 175 ms | 7680 KB |
1_41.txt | AC | 89 ms | 5632 KB |
1_42.txt | AC | 218 ms | 14208 KB |
1_43.txt | AC | 52 ms | 5376 KB |
1_44.txt | AC | 218 ms | 14464 KB |
1_45.txt | AC | 61 ms | 5504 KB |
1_46.txt | AC | 246 ms | 17920 KB |
1_47.txt | AC | 78 ms | 5632 KB |
1_48.txt | AC | 252 ms | 18048 KB |
1_49.txt | AC | 49 ms | 5376 KB |
1_50.txt | AC | 260 ms | 18944 KB |
1_51.txt | AC | 54 ms | 5248 KB |
1_52.txt | AC | 262 ms | 19200 KB |
1_53.txt | AC | 49 ms | 5376 KB |
1_54.txt | AC | 251 ms | 19584 KB |
1_55.txt | AC | 78 ms | 5504 KB |
1_56.txt | AC | 255 ms | 19712 KB |
1_57.txt | AC | 65 ms | 5504 KB |
1_58.txt | AC | 255 ms | 19328 KB |
1_59.txt | AC | 81 ms | 5632 KB |
1_60.txt | AC | 254 ms | 19840 KB |
1_61.txt | AC | 61 ms | 5504 KB |
1_62.txt | AC | 264 ms | 20608 KB |
1_63.txt | AC | 80 ms | 5376 KB |
1_64.txt | AC | 250 ms | 19584 KB |
1_65.txt | AC | 49 ms | 5376 KB |
1_66.txt | AC | 261 ms | 21760 KB |
1_67.txt | AC | 71 ms | 5504 KB |
1_68.txt | AC | 293 ms | 22656 KB |
1_69.txt | AC | 46 ms | 5376 KB |