#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define s second
#define f first
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(k[0] == v[2] && k[2] == v[4] && k[1] == v[1] && k[3] == v[3]) 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]}]++;
// if(i+1 == n) cerr<<"ANS: "<<ans<<endl;
ans+= m1234[find(v)];
// cerr<<"ANS: "<<ans<<" "<<v[2]<<v[3]<<v[4]<<" "<<m123[{v[2],v[3],v[4]}]<<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]}];
}
// cerr<<"ANS: "<<ans<<" "<<v[1]<<v[2]<<v[4]<<" "<<m134[{v[1],v[2],v[4]}]<<endl;
if(v[1] == v[4] && m134.find({v[1],v[3]}) != m134.end()){
ans-=m123[{v[1],v[3]}];
}
vector<char> v1 = {v[2],v[1],v[4],v[3]};
if(v[1] != v[2] && v[3] != v[4] && 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])){
// 3!
ans-=m1234[v1];
}
v1 = {v[3],v[4],v[1],v[2]}; // TAKE CARE OF 2 AND 3
if(v[1] != v[2] && v[3] != v[4] && m1234.find(v1) != m1234.end()){
ans-=m1234[v1];
}
if((v[1] == v[3] || v[2] == v[4]) && !(v[4] == v[2] && v[3] == v[1])){
// 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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1010 ms |
37060 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
124 ms |
5852 KB |
Output is correct |
3 |
Correct |
955 ms |
33384 KB |
Output is correct |
4 |
Correct |
451 ms |
19588 KB |
Output is correct |
5 |
Correct |
432 ms |
19608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |