Submission #477355

# Submission time Handle Problem Language Result Execution time Memory
477355 2021-10-01T18:32:38 Z BThero Cards (LMIO19_korteles) C++17
16 / 100
1000 ms 71756 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

using namespace std;

typedef long long ll;

const int MAXN = (int)5e5 + 5;

array<int, 2> arr[MAXN][4];
int cnt[16][MAXN];
string str[MAXN];
int mem[MAXN][16];
int n;

int f(char c) {
	return c - 'A';
}

bool bit(int x, int p) {
	return x & (1 << p);
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;

	for (int i = 0; i < n; i++) {
		string x, y;
		cin >> x >> y;
		str[i] = x + y;
		arr[i][0] = {0, 1};
		arr[i][1] = {0, 2};
		arr[i][2] = {1, 3};
		arr[i][3] = {2, 3};

		for (int mask = 1; mask < 16; mask++) {
			vector<int> used(4, 0);
			int cur = 0;

			for (int j = 0; j < 4; j++) {
				if (bit(mask, j)) {
					for (int x : arr[i][j]) {
						if (!used[x]) {
							cur = cur * 26 + f(str[i][x]);
							used[x] = 1;
						}
					}
				}
			}

			mem[i][mask] = cur;
		}
	}

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		for (int mask = 1; mask < 16; mask++) {
			int pp = __builtin_popcount(mask);

			if (pp % 2 == 1) {
				ans += cnt[mask][mem[i][mask]];
			}
			else {
				ans -= cnt[mask][mem[i][mask]];
			}
		}

		reverse(arr[i], arr[i] + 4);

		for (int mask = 1; mask < 16; mask++) {
			vector<int> used(4, 0);
			int cur = 0;

			for (int j = 0; j < 4; j++) {
				if (bit(mask, j)) {
					for (int x : arr[i][j]) {
						if (!used[x]) {
							cur = cur * 26 + f(str[i][x]);
							used[x] = 1;
						}
					}
				}
			}

			cnt[mask][cur]++;
		}
	}

	cout << ans << '\n';
	return 0;
}

# Verdict Execution time Memory Grader output
1 Correct 8 ms 16076 KB Output is correct
2 Correct 10 ms 16460 KB Output is correct
3 Correct 9 ms 16972 KB Output is correct
4 Correct 10 ms 17484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16076 KB Output is correct
2 Correct 10 ms 16460 KB Output is correct
3 Correct 9 ms 16972 KB Output is correct
4 Correct 10 ms 17484 KB Output is correct
5 Incorrect 8 ms 16076 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1006 ms 71756 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16076 KB Output is correct
2 Incorrect 117 ms 33528 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 16076 KB Output isn't correct
2 Halted 0 ms 0 KB -