이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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!
if(v[1] == v[2]){
// what should i do with this? v1 matches 3
ans-= m1234[v1];
}
else{
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[2] || v[3] == v[4]) && !(v[1] == v[2] && v[3] == v[4])){
// 3!
if(v[1] == v[2]){
// what should i do with this? v1 matches 3
ans-= m1234[v1];
}
else{
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |