Submission #1690224
Source Code Expand
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// _oo0oo_ //
// o8888888o //
// 88" . "88 ------ hzt1 //
// (| -_- |) //
// 0\ = /0 //
// ___/`---'\___ //
// .' \| |// '. //
// / \||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \ - /// | | //
// | \_| ''\---/'' |_/ | //
// \ .-\__ '-' ___/-. / //
// ___'. .' /--.--\ `. .'___ //
// ."" '< `.___\_<|>_/___.' >' "". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `_. \_ __\ /__ _/ .-` / / //
// =====`-.____`.___ \_____/___.-`___.-'===== //
// `=---=' //
// //
// //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// //
// God-He Bless All. //
// This Code Will Never Explode. //
// //
// //
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
#include<cstdio>
#include<cstring>
#include<cctype>
#include<map>
#include<algorithm>
#define rep(i,a,b) for(int i=(a),i##_end_=(b);i<=i##_end_;i++)
#define dwn(i,a,b) for(int i=(a),i##_end_=(b);i>=i##_end_;i--)
using namespace std;
const int Size=1<<16;
char buffer[Size],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,Size,stdin);
tail=(head=buffer)+l;
}
if(head==tail) return -1;
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
typedef long long ll;
const int maxn=410;
struct State {
int a,b,c,d;
bool operator < (const State& S) const {
if(a!=S.a) return a<S.a;
if(b!=S.b) return b<S.b;
if(c!=S.c) return c<S.c;
return d<S.d;
}
bool operator == (const State& S) {
return a==S.a&&b==S.b&&c==S.c&&d==S.d;
}
}A[maxn][4];
const int HASH=152501;
struct Hash_Table {
int first[HASH],nxt[maxn*4],sum[maxn*4],cnt;
ll val[maxn*4];
int find(ll x) {
int p=x%HASH;if(p<0) p+=HASH;
for(int i=first[p];i;i=nxt[i]) if(val[i]==x) return sum[i];
return -1;
}
void add(ll x) {
int p=x%HASH;if(p<0) p+=HASH;
for(int i=first[p];i;i=nxt[i]) if(val[i]==x) {sum[i]++;return;}
val[++cnt]=x;sum[cnt]=1;nxt[cnt]=first[p];first[p]=cnt;
}
void del(ll x) {
int p=x%HASH;if(p<0) p+=HASH;
for(int i=first[p];i;i=nxt[i]) if(val[i]==x) {sum[i]--;return;}
}
}M;
#define hash(a,b,c,d) ((a+1)*201525010ll+(b+1)*252501ll+(c+1)*2501+d+1)
void del(State x) {
M.del(hash(x.a,x.b,x.c,x.d));
M.del(hash(x.b,x.c,x.d,x.a));
M.del(hash(x.c,x.d,x.a,x.b));
M.del(hash(x.d,x.a,x.b,x.c));
}
void add(State x) {
M.add(hash(x.a,x.b,x.c,x.d));
M.add(hash(x.b,x.c,x.d,x.a));
M.add(hash(x.c,x.d,x.a,x.b));
M.add(hash(x.d,x.a,x.b,x.c));
}
int main() {
int n=read();
rep(i,1,n) {
int a=read(),b=read(),c=read(),d=read();
A[i][0]=(State){a,b,c,d};
A[i][1]=(State){b,c,d,a};
A[i][2]=(State){c,d,a,b};
A[i][3]=(State){d,a,b,c};
M.add(hash(a,b,c,d));M.add(hash(c,d,a,b));
M.add(hash(b,c,d,a));M.add(hash(d,a,b,c));
}
ll ans=0;
rep(i,1,n) rep(j,i+1,n) if(i!=j) {
del(A[i][0]);del(A[j][0]);
rep(y,0,3) {
swap(A[j][y].a,A[j][y].b);swap(A[j][y].c,A[j][y].d);
State S[4];
S[0]=(State){A[i][0].b,A[i][0].a,A[j][y].a,A[j][y].b};
S[1]=(State){A[j][y].b,A[j][y].c,A[i][0].c,A[i][0].b};
S[2]=(State){A[i][0].d,A[i][0].c,A[j][y].c,A[j][y].d};
S[3]=(State){A[j][y].a,A[i][0].a,A[i][0].d,A[j][y].d};
int c1=M.find(hash(A[i][0].b,A[i][0].a,A[j][y].a,A[j][y].b));del(S[0]);
int c2=M.find(hash(A[j][y].b,A[j][y].c,A[i][0].c,A[i][0].b));del(S[1]);
int c3=M.find(hash(A[i][0].d,A[i][0].c,A[j][y].c,A[j][y].d));del(S[2]);
int c4=M.find(hash(A[j][y].a,A[i][0].a,A[i][0].d,A[j][y].d));del(S[3]);
if(c1>0&&c2>0&&c3>0&&c4>0) ans+=(ll)c1*c2*c3*c4;
if(c1!=-1) add(S[0]);
if(c2!=-1) add(S[1]);
if(c3!=-1) add(S[2]);
if(c4!=-1) add(S[3]);
swap(A[j][y].a,A[j][y].b);swap(A[j][y].c,A[j][y].d);
}
add(A[i][0]);add(A[j][0]);
}
printf("%lld\n",ans/3);
return 0;
}
Submission Info
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 900 |
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, 1_015.txt, 1_016.txt, 1_017.txt, 1_018.txt, 1_019.txt |
Case Name |
Status |
Exec Time |
Memory |
0_000.txt |
AC |
1 ms |
256 KB |
0_001.txt |
AC |
1 ms |
256 KB |
0_002.txt |
AC |
0 ms |
128 KB |
1_003.txt |
AC |
69 ms |
256 KB |
1_004.txt |
AC |
5 ms |
128 KB |
1_005.txt |
AC |
69 ms |
256 KB |
1_006.txt |
AC |
49 ms |
256 KB |
1_007.txt |
AC |
69 ms |
256 KB |
1_008.txt |
AC |
61 ms |
256 KB |
1_009.txt |
WA |
98 ms |
512 KB |
1_010.txt |
WA |
14 ms |
512 KB |
1_011.txt |
WA |
69 ms |
768 KB |
1_012.txt |
AC |
1 ms |
512 KB |
1_013.txt |
AC |
49 ms |
768 KB |
1_014.txt |
AC |
1 ms |
640 KB |
1_015.txt |
AC |
50 ms |
768 KB |
1_016.txt |
AC |
14 ms |
768 KB |
1_017.txt |
AC |
50 ms |
768 KB |
1_018.txt |
AC |
50 ms |
768 KB |
1_019.txt |
AC |
50 ms |
768 KB |