Submission #1364609
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
using i64=int64_t;
void shift(vector<int> &a){
rotate(a.begin(),a.begin()+1,a.end());
};
void normalize(vector<int>& a){
auto amin=a;
rep(i,0,4){
amin=min(amin,a);
shift(a);
}
a=amin;
}
i64 encode(vector<int>& a){
i64 res=0;
rep(i,0,4){
res*=1000;
res+=a[i];
}
return res;
}
vector<int> reverse(vector<int> &a){
auto b=a;
swap(b[0],b[1]);
swap(b[3],b[2]);
return b;
}
int f(vector<int>& a){
if(a[0]==a[1] and a[1]==a[2] and a[2]==a[3]) return 4;
if(a[0]==a[2] and a[1]==a[3]) return 2;
return 1;
}
void input(int& N,vector<vector<int>> &C){
cin >> N;
C.resize(N);
rep(i,0,N){
C[i].resize(4);
cin >> C[i][0] >> C[i][1] >> C[i][2] >> C[i][3];
normalize(C[i]);
}
}
void solve(){
int N;
vector<vector<int>> C;
input(N,C);
map<i64,i64> count[5]; //1,2,4
rep(i,0,N) ++count[f(C[i])][encode(C[i])];
auto make_sides=[&](int i,int j){
vector<vector<int>> sides(4,vector<int>(4));
rep(k,0,4){
sides[k][0]=C[i][(k+1)%4];
sides[k][1]=C[i][k];
sides[k][2]=C[j][k];
sides[k][3]=C[j][(k+1)%4];
}
return sides;
};
i64 ans=0;
rep(i,0,N){
--count[f(C[i])][encode(C[i])];
rep(j,i+1,N){
--count[f(C[j])][encode(C[j])];
C[j]=reverse(C[j]);
rep(k,0,4){
auto sides=make_sides(i,j);
for(auto &side:sides) normalize(side);
i64 tmp1=1;
rep(i_,0,4){
i64 tmp2=count[f(sides[i_])][encode(sides[i_])];
rep(j_,0,i_) if(encode(sides[j_])==encode(sides[i_])) --tmp2;
tmp1*=tmp2*f(sides[i_]);
}
ans+=tmp1;
shift(C[j]);
}
C[j]=reverse(C[j]);
++count[f(C[j])][encode(C[j])];
}
}
cout << ans << endl;
}
int main(){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
solve();
return 0;
}
Submission Info
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
0_000.txt, 0_001.txt, 0_002.txt |
All |
0_000.txt, 0_001.txt, 0_002.txt, 1_003.txt, 1_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt |
Case Name |
Status |
Exec Time |
Memory |
0_000.txt |
WA |
1 ms |
256 KB |
0_001.txt |
WA |
1 ms |
256 KB |
0_002.txt |
WA |
1 ms |
256 KB |
1_003.txt |
WA |
1 ms |
256 KB |
1_004.txt |
WA |
1678 ms |
384 KB |
1_005.txt |
WA |
70 ms |
256 KB |
1_006.txt |
WA |
250 ms |
384 KB |
1_007.txt |
WA |
92 ms |
256 KB |
1_008.txt |
WA |
18 ms |
384 KB |
1_009.txt |
WA |
9 ms |
640 KB |
1_010.txt |
WA |
4 ms |
512 KB |
1_011.txt |
WA |
7 ms |
256 KB |
1_012.txt |
WA |
19 ms |
256 KB |
1_013.txt |
WA |
1690 ms |
256 KB |
1_014.txt |
WA |
1721 ms |
384 KB |