답안 #148681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
148681 2019-09-01T04:54:54 Z Greedy left the chat.(#3618, miguel, claudy, MvC) 함수컵 박물관 (FXCUP4_museum) C++17
100 / 100
579 ms 14696 KB
#include "museum.h"
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
/*
# include <ext/pb_ds/tree_policy.hpp>
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/rope>
*/
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;

/*
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
Tree<int>tr;
*/

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int f[105][105][105];


#undef int
ll calc(vector<int>vec){
#define int ll
	# define f g
	ll f[105];
	memset(f,0,sizeof(f));
	for(auto it : vec) f[it]++;
	ll ans = 0;
	for(int i = 1;i <= 100;i++) {
		ans += 1ll * (f[i] - 1) * f[i];
	}
	#undef f
	return ans;
}


#undef int
long long CountSimilarPairs(std::vector<int> B, std::vector<int> T, std::vector<int> G)
{
#define int ll
	int n = sz(B);
	for(int i = 0;i < n;i++) f[B[i]][T[i]][G[i]]++;
	int ans = 0;
	ans += calc(B);
	ans += calc(T);
	ans += calc(G);
	for(int a = 1;a <= 100;a++){
		for(int b = 1;b <= 100;b++){
			for(int c = 1;c <= 100;c++){
				ans -= 2 * (f[a][b][c]) * (f[a][b][c] - 1);
			}
		}
	}
	for(int i = 0;i < n;i++){
		vector<int>vec(3),c(3);
		vec[0] = B[i];
		vec[1] = T[i];
		vec[2] = G[i];
		for(int j = 0;j < 3;j++){
			c[0] = vec[0];c[1] = vec[1];c[2] = vec[2];
			for(int x = 1;x <= 100;x++){
				if(x == vec[j]) continue;
				c[j] = x;
				ans -= f[c[0]][c[1]][c[2]];
			}
		}
	}
	return ans / 2;
}

Compilation message

museum.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 # pragma GCC optimization ("unroll-loops")
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 10 ms 1792 KB Output is correct
6 Correct 10 ms 2736 KB Output is correct
7 Correct 12 ms 3584 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 14 ms 5632 KB Output is correct
10 Correct 16 ms 5376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 9 ms 512 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 10 ms 1792 KB Output is correct
6 Correct 10 ms 2736 KB Output is correct
7 Correct 12 ms 3584 KB Output is correct
8 Correct 11 ms 512 KB Output is correct
9 Correct 14 ms 5632 KB Output is correct
10 Correct 16 ms 5376 KB Output is correct
11 Correct 30 ms 8448 KB Output is correct
12 Correct 41 ms 1280 KB Output is correct
13 Correct 172 ms 9076 KB Output is correct
14 Correct 306 ms 11376 KB Output is correct
15 Correct 403 ms 12528 KB Output is correct
16 Correct 210 ms 5988 KB Output is correct
17 Correct 219 ms 6120 KB Output is correct
18 Correct 257 ms 8292 KB Output is correct
19 Correct 545 ms 14692 KB Output is correct
20 Correct 579 ms 14696 KB Output is correct