# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
376029 |
2021-03-10T17:22:28 Z |
Aldas25 |
Cards (LMIO19_korteles) |
C++14 |
|
725 ms |
31964 KB |
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MAXN = 500100, MAXK = 23;
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ld PI = asin(1) * 2;
void setIO () {
FAST_IO;
}
void setIO (string s) {
setIO();
freopen((s+".in").c_str(),"r",stdin);
freopen((s+".out").c_str(),"w",stdout);
}
int hsh (int a, int b) {
return a*26 + b;
}
int hsh (int a, int b, int c) {
return a*26*26 + b*26 + c;
}
int hsh (int a, int b, int c, int d) {
return a*26*26*26 + b*26*26 + c*26 + d;
}
int n;
int cards[MAXN][2][2];
unordered_map<int, ll> cntUp, cntDown, cntRight, cntLeft;
unordered_map<int, ll> cntAll;
unordered_map<int, ll> cntUL, cntUR, cntDL, cntDR;
int main() {
setIO();
cin >> n;
FOR(i, 1, n) FOR(j, 0, 1) FOR(k, 0, 1) {
char c; cin >> c;
cards[i][j][k] = (c-'A');
}
ll ans = 0;
FOR(i, 1, n) {
int a = cards[i][0][0], b = cards[i][0][1];
int c = cards[i][1][0], d = cards[i][1][1];
ll cur = 0;
cur += cntUp[hsh(c,d)];
cur += cntDown[hsh(a,b)];
cur += cntLeft[hsh(b,d)];
cur += cntRight[hsh(a,c)];
cur -= cntAll[hsh(c, d, a, b)];
cur -= cntAll[hsh(b, a, d, c)];
if (a == d) {
cur -= cntUR[hsh(c, a, c)];
cur -= cntDL[hsh(b, a, b)];
}
if (b == c) {
cur -= cntUL[hsh(b, d, d)];
cur -= cntDR[hsh(a, a, b)];
}
if (a == d && b == c) {
cur += 3*cntAll[hsh(b, a, a, b)];
}
ans += cur;
cntUp[hsh(a,b)]++;
cntLeft[hsh(a,c)]++;
cntRight[hsh(b,d)]++;
cntDown[hsh(c,d)]++;
cntAll[hsh(a,b,c,d)]++;
cntUL[hsh(a,b,c)]++;
cntUR[hsh(a,b,d)]++;
cntDL[hsh(a,c,d)]++;
cntDR[hsh(b,c,d)]++;
}
cout << ans << "\n";
return 0;
}
Compilation message
korteles.cpp: In function 'void setIO(std::string)':
korteles.cpp:34:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
34 | freopen((s+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
korteles.cpp:35:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
35 | freopen((s+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
620 KB |
Output is correct |
7 |
Correct |
2 ms |
492 KB |
Output is correct |
8 |
Correct |
4 ms |
1260 KB |
Output is correct |
9 |
Correct |
4 ms |
1024 KB |
Output is correct |
10 |
Correct |
5 ms |
876 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
725 ms |
29488 KB |
Output is correct |
2 |
Correct |
692 ms |
31964 KB |
Output is correct |
3 |
Correct |
703 ms |
31852 KB |
Output is correct |
4 |
Correct |
653 ms |
31964 KB |
Output is correct |
5 |
Correct |
653 ms |
31708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
88 ms |
10896 KB |
Output is correct |
3 |
Correct |
444 ms |
23772 KB |
Output is correct |
4 |
Correct |
305 ms |
20660 KB |
Output is correct |
5 |
Correct |
283 ms |
20680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
4 ms |
1260 KB |
Output is correct |
5 |
Correct |
4 ms |
1024 KB |
Output is correct |
6 |
Correct |
5 ms |
876 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
725 ms |
29488 KB |
Output is correct |
13 |
Correct |
692 ms |
31964 KB |
Output is correct |
14 |
Correct |
703 ms |
31852 KB |
Output is correct |
15 |
Correct |
653 ms |
31964 KB |
Output is correct |
16 |
Correct |
653 ms |
31708 KB |
Output is correct |
17 |
Correct |
88 ms |
10896 KB |
Output is correct |
18 |
Correct |
444 ms |
23772 KB |
Output is correct |
19 |
Correct |
305 ms |
20660 KB |
Output is correct |
20 |
Correct |
283 ms |
20680 KB |
Output is correct |
21 |
Correct |
190 ms |
15284 KB |
Output is correct |
22 |
Correct |
514 ms |
29560 KB |
Output is correct |
23 |
Correct |
368 ms |
25272 KB |
Output is correct |
24 |
Correct |
397 ms |
25180 KB |
Output is correct |