Submission #148937

# Submission time Handle Problem Language Result Execution time Memory
148937 2019-09-01T05:25:31 Z Fenwick_team(#3609, amiratou, AyaBenSaad, Nucleist) FunctionCup Museum (FXCUP4_museum) C++17
27 / 100
13 ms 4352 KB
#include "museum.h"
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
/*int p[200002][3];
ll s[200002][3];
int find_set(int i,int id){
	if(i==p[i][id])return i;
	return p[i][id]=find_set(p[i][id],id);
}
void Union(int a,int b,int id){
	for (int i = 0; i < 3; ++i)
	{
		int x=find_set(a,i),y=find_set(b,i);
		if(x==y)return ;
	}
	int x=find_set(a,id),y=find_set(b,id);
	p[y][id]=x,s[x][id]+=s[y][id];
}*/
bool done[2002][2002];
ll CountSimilarPairs(v B, v T, v G) {
	int N = sz(B);
	ll ans=0;
	//for (int i = 0; i < N; ++i)
	//	s[i][0]=s[i][1]=s[i][2]=1,p[i][0]=p[i][1]=p[i][2]=i;
	vii BB(N),TT(N),GG(N);
	for (int i = 0; i < N; ++i)
		BB[i]=ii(B[i],i),TT[i]=ii(T[i],i),GG[i]=ii(G[i],i);
	sort(all(BB)),sort(all(TT)),sort(all(GG));
	for (int i = 0; i < N;)
	{
		int j=i+1;
		v vec;vec.pb(BB[i].se);
		while(j<N&&BB[i].fi==BB[j].fi){
			//debugs(BB[i].se,BB[j].se);
			//Union(BB[i].se,BB[j].se,0);
			vec.pb(BB[j].se);
			j++;
		}
		for (int a = 0; a < sz(vec); ++a)
			for (int b = a+1; b < sz(vec); ++b)
				if(!done[vec[a]][vec[b]]||!done[vec[b]][vec[a]])
					done[vec[a]][vec[b]]=done[vec[b]][vec[a]]=1,ans++;
		i=j;
	}
	for (int i = 0; i < N;)
	{
		int j=i+1;
		v vec;vec.pb(TT[i].se);
		while(j<N&&TT[i].fi==TT[j].fi){
			//debugs(TT[i].se,TT[j].se);
			//Union(TT[i].se,TT[j].se,0);
			vec.pb(TT[j].se);
			j++;
		}
		for (int a = 0; a < sz(vec); ++a)
			for (int b = a+1; b < sz(vec); ++b)
				if(!done[vec[a]][vec[b]]||!done[vec[b]][vec[a]])
					done[vec[a]][vec[b]]=done[vec[b]][vec[a]]=1,ans++;
		i=j;
	}for (int i = 0; i < N;)
	{
		int j=i+1;
		v vec;vec.pb(GG[i].se);
		while(j<N&&GG[i].fi==GG[j].fi){
			//debugs(GG[i].se,GG[j].se);
			//Union(GG[i].se,GG[j].se,0);
			vec.pb(GG[j].se);
			j++;
		}
		for (int a = 0; a < sz(vec); ++a)
			for (int b = a+1; b < sz(vec); ++b)
				if(!done[vec[a]][vec[b]]||!done[vec[b]][vec[a]])
					done[vec[a]][vec[b]]=done[vec[b]][vec[a]]=1,ans++;
		i=j;
	}
	/*set<ii> myset;
	for (int i = 0; i < N; ++i){
		for (int j = 1; j < 3; ++j)
		{
			int x=find_set(i,j);
			//debugs(s[x][j],j);
			if(find_set(x,0)!=find_set(i,0))
				s[x][0]++,myset.insert(ii(find_set(x,0),0));
		}
		//sep()
	}
	ll ans=0;
	for(auto it:myset){
		debugii(it);
		debug(s[it.fi][it.se]);
		//debugs(it,s[it]);
		ans+=(s[it.fi][it.se]*(s[it.fi][it.se]-1LL))/2LL;
	}*/
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 6 ms 1024 KB Output is correct
6 Correct 7 ms 1920 KB Output is correct
7 Correct 7 ms 2432 KB Output is correct
8 Correct 13 ms 4352 KB Output is correct
9 Correct 9 ms 4352 KB Output is correct
10 Correct 9 ms 4352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 640 KB Output is correct
5 Correct 6 ms 1024 KB Output is correct
6 Correct 7 ms 1920 KB Output is correct
7 Correct 7 ms 2432 KB Output is correct
8 Correct 13 ms 4352 KB Output is correct
9 Correct 9 ms 4352 KB Output is correct
10 Correct 9 ms 4352 KB Output is correct
11 Runtime error 9 ms 796 KB Execution killed with signal 11 (could be triggered by violating memory limits)
12 Halted 0 ms 0 KB -