답안 #287844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
287844 2020-09-01T04:15:02 Z nandonathaniel Cards (LMIO19_korteles) C++14
100 / 100
63 ms 4860 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXEMPAT=457000,MAXDUA=680;
int kiri[MAXDUA],kanan[MAXDUA],atas[MAXDUA],bawah[MAXDUA],cnt[MAXEMPAT];

int dua(int x,int y){
	return 26*x+y;
}

int empat(int u,int v,int x,int y){
	return 26*26*26*u+26*26*v+26*x+y;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	int n;
	long long ans=0;
	char a,b,c,d;
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a >> b >> c >> d;
		cnt[empat(a-'A',b-'A',c-'A',d-'A')]++;
		kiri[dua(a-'A',c-'A')]++;
		kanan[dua(b-'A',d-'A')]++;
		atas[dua(a-'A',b-'A')]++;
		bawah[dua(c-'A',d-'A')]++;
	}
	for(int i=0;i<676;i++){
		ans+=1LL*kiri[i]*kanan[i];
		ans+=1LL*atas[i]*bawah[i];
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<26;j++){
			for(int k=0;k<26;k++){
				for(int l=0;l<26;l++){
					int x=empat(i,j,k,l),y=empat(k,l,i,j);
					if(x<y)ans-=1LL*cnt[x]*cnt[y];
					y=empat(j,i,l,k);
					if(x<y)ans-=1LL*cnt[x]*cnt[y];
				}
			}
		}
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<26;j++){
			for(int k=0;k<26;k++){
				for(int l=0;l<26;l++){
					int x=empat(k,i,i,j),y=empat(i,j,j,l);
					if(x!=y)ans-=1LL*cnt[x]*cnt[y];
					x=empat(i,j,k,i);y=empat(j,l,i,j);
					if(x!=y)ans-=1LL*cnt[x]*cnt[y];
				}
			}
		}
	}
	//inklusi eksklusi
	for(int i=0;i<26;i++){
		for(int j=i+1;j<26;j++){
			int x=empat(i,j,j,i),y=empat(j,i,i,j);
			ans+=3LL*cnt[x]*cnt[y];
		}
		ans-=2LL*cnt[empat(i,i,i,i)];
	}
	for(int i=0;i<26;i++){
		for(int j=0;j<26;j++){
			if(i==j)continue;
			ans-=1LL*cnt[empat(i,j,i,j)];
			ans-=1LL*cnt[empat(i,i,j,j)];
		}
	}
	cout << ans << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 2176 KB Output is correct
5 Correct 4 ms 1536 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 4856 KB Output is correct
2 Correct 51 ms 4860 KB Output is correct
3 Correct 63 ms 4856 KB Output is correct
4 Correct 46 ms 4856 KB Output is correct
5 Correct 52 ms 4856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 8 ms 2432 KB Output is correct
3 Correct 40 ms 3940 KB Output is correct
4 Correct 20 ms 3200 KB Output is correct
5 Correct 19 ms 3200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 1664 KB Output is correct
3 Correct 3 ms 640 KB Output is correct
4 Correct 4 ms 2176 KB Output is correct
5 Correct 4 ms 1536 KB Output is correct
6 Correct 4 ms 1920 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 43 ms 4856 KB Output is correct
13 Correct 51 ms 4860 KB Output is correct
14 Correct 63 ms 4856 KB Output is correct
15 Correct 46 ms 4856 KB Output is correct
16 Correct 52 ms 4856 KB Output is correct
17 Correct 8 ms 2432 KB Output is correct
18 Correct 40 ms 3940 KB Output is correct
19 Correct 20 ms 3200 KB Output is correct
20 Correct 19 ms 3200 KB Output is correct
21 Correct 13 ms 2688 KB Output is correct
22 Correct 36 ms 4216 KB Output is correct
23 Correct 31 ms 3464 KB Output is correct
24 Correct 23 ms 3456 KB Output is correct