# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
895623 |
2023-12-30T11:55:04 Z |
vjudge1 |
Cards (LMIO19_korteles) |
C++17 |
|
1000 ms |
34888 KB |
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define s second
#define f first
int check1(vector<char> a, vector<char> b){
int ans = 0;
if(a[0] == b[3] && a[1] == b[4]) ans++;
if(a[0] == b[2] && a[2] == b[4]) ans++;
if(a[1] == b[1] && a[3] == b[3]) ans++;
if(a[2] == b[1] && a[3] == b[2]) ans++;
return ans;
}
vector<char> find(vector<char> v){
vector<char> k(4,' ');
k[3-1] = v[1]; k[4-1] = v[2];
k[0] = v[3]; k[2-1] = v[4];
if(check1(k,v) == 4) return k;
return {};
}
signed main(){
int n; cin>>n;
map<pair<char,char>,int> m12,m13,m34,m24;
map<vector<char>,int> m1234,m123, m124, m134, m234;
int ans = 0;
for(int i = 0; i<n; i++){
// 100% CHECKED
vector<char> v(5); cin>>v[1]>>v[2]>>v[3]>>v[4];
if(m34.find({v[1],v[2]}) != m34.end()){
ans+= m34[{v[1],v[2]}];
}
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
if(m12.find({v[3],v[4]}) != m12.end()){
ans+= m12[{v[3],v[4]}];
}
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
if(m13.find({v[2],v[4]}) != m13.end()){
ans+= m13[{v[2],v[4]}];
}
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
if(m24.find({v[1],v[3]}) != m24.end()){
ans+= m24[{v[1],v[3]}];
}
// cerr<<"ANS: "<<ans<<" "<<v[1]<<v[2]<<v[3]<<" "<<m234[{v[1],v[2],v[3]}]<<endl;
if(v[2] == v[3] && m234.find({v[2],v[4]}) != m234.end()){
ans-=m234[{v[2],v[4]}];
}
if(v[2] == v[3]) m234[{v[1],v[3]}]++;
vector<char> v3 =find(v);
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
ans+= m1234[v3];
// cerr<<"HERE ANS: "<<ans<<" "<<m1234[find(v)]<<endl;
if(v[2] == v[3] && m123.find({v[1],v[2]}) != m123.end()){
ans-=m123[{v[1],v[2]}];
}
// cerr<<"ANS: "<<ans<<" "<<v[1]<<v[3]<<v[4]<<" "<<m124[{v[1],v[3],v[4]}]<<endl;
if(v[1] == v[4] && m124.find({v[1],v[2]}) != m124.end()){
ans-=m124[{v[1],v[2]}];
}
if(v[1] == v[4] && m134.find({v[1],v[3]}) != m134.end()){
ans-=m134[{v[1],v[3]}];
}
// cerr<<"ANS: "<<ans<<" "<<v[1]<<v[2]<<v[4]<<" "<<m134[{v[1],v[2],v[4]}]<<endl;
vector<char> v1 = {v[2],v[1],v[4],v[3]};
if(v1 != v3 && !(v[1] == v[2] && v[3] == v[4] && v[1] == v[3]) && m1234.find(v1) != m1234.end()){
ans-=m1234[{v[2],v[1],v[4],v[3]}];
}
// if((v[1] == v[2] || v[3] == v[4]) && !(v[1] == v[2] && v[3] == v[4])&& m1234.find(v1) != m1234.end()){
// // 3!
// ans+=m1234[v1];
// }
vector<char> v2 = {v[3],v[4],v[1],v[2]}; // TAKE CARE OF 2 AND 3
if(v2 != v3 && v1 != v2 && !(v[1] == v[3] && v[2] == v[4] && v[1] == v[2]) && m1234.find(v2) != m1234.end()){
ans-=m1234[v2];
}
// if((v[1] == v[3] || v[2] == v[4]) && !(v[4] == v[2] && v[3] == v[1])&& m1234.find(v1) != m1234.end()){
// // 3!
// ans+=m1234[v1];
// }
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
m12[{v[1],v[2]}]++;
m13[{v[1],v[3]}]++;
m34[{v[3],v[4]}]++;
m24[{v[2],v[4]}]++;
m1234[{v[1],v[2],v[3],v[4]}]++;
if(v[4] == v [1]) m134[{v[2],v[4]}]++;
if(v[1] == v[4]) m124[{v[3],v[4]}]++;
if(v[2] == v[3]) m123[{v[2],v[4]}]++;
}
cout<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
628 KB |
Output is correct |
8 |
Correct |
5 ms |
860 KB |
Output is correct |
9 |
Correct |
5 ms |
604 KB |
Output is correct |
10 |
Correct |
5 ms |
604 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1050 ms |
34888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
116 ms |
6012 KB |
Output is correct |
3 |
Correct |
984 ms |
33364 KB |
Output is correct |
4 |
Correct |
439 ms |
19536 KB |
Output is correct |
5 |
Correct |
502 ms |
19752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
628 KB |
Output is correct |
4 |
Correct |
5 ms |
860 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
5 ms |
604 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Execution timed out |
1050 ms |
34888 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |