답안 #477353

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477353 2021-10-01T18:11:59 Z BThero Cards (LMIO19_korteles) C++17
36 / 100
1000 ms 67548 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;

unordered_map<ll, int> cnt[16];
array<int, 4> arr[MAXN];
int n;

int encode(char a, char b) {
	return (a - 'A') * 26 + (b - '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;
		arr[i][0] = encode(x[0], x[1]);
		arr[i][1] = encode(x[0], y[0]);
		arr[i][2] = encode(x[1], y[1]);
		arr[i][3] = encode(y[0], y[1]);
	}

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		for (int mask = 1; mask < 16; mask++) {
			ll cur = 0;

			for (int j = 0; j < 4; j++) {
				if (bit(mask, j)) {
					cur = cur * 26 * 26 + arr[i][j];
				}
			}

			int pp = __builtin_popcount(mask);
			auto it = cnt[mask].find(cur);
			ll tmp = (it == cnt[mask].end() ? 0 : it -> second);

			if (pp % 2 == 1) {
				ans += tmp;
			}
			else {
				ans -= tmp;
			}
		}

		reverse(all(arr[i]));

		for (int mask = 1; mask < 16; mask++) {
			ll cur = 0;

			for (int j = 0; j < 4; j++) {
				if (bit(mask, j)) {
					cur = cur * 26 * 26 + arr[i][j];
				}
			}

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

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

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 3 ms 896 KB Output is correct
8 Correct 6 ms 1612 KB Output is correct
9 Correct 6 ms 1484 KB Output is correct
10 Correct 7 ms 1484 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1085 ms 67548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 267 ms 19372 KB Output is correct
3 Execution timed out 1098 ms 66244 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 3 ms 896 KB Output is correct
4 Correct 6 ms 1612 KB Output is correct
5 Correct 6 ms 1484 KB Output is correct
6 Correct 7 ms 1484 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Execution timed out 1085 ms 67548 KB Time limit exceeded
13 Halted 0 ms 0 KB -