#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n,satu,dua,empat,u,d,l,r;
vector<vector<int> > pairu(676*676),paird(676*676),pairr(676*676),pairl(676*676);
bool tmp1[680],tmp2[680],tmp3[680],tmp4[680];
bool ada[676*676];
string s[676*676],abaw,tms1,tms2,kaki,tms,a,b;
int hsh(string a){
return int(a[0]-'A')* 676*26+int(a[1]-'A')*676+int(a[2]-'A')*26+int(a[3]-'A');
}
void ts(string &x, char a, char b, char c , char d){
x.pb(a);
x.pb(b);
x.pb(c);
x.pb(d);
}
int main(){
cin>>n;
for(int i =1;i<=n;i++){
a,b;
cin>>a>>b;
s[i] = a+b;
u = (s[i][0]-'A')*26+ (s[i][1]-'A');
d = (s[i][2]-'A')*26+ (s[i][3]-'A');
l = (s[i][0]-'A')*26+ (s[i][2]-'A');
r = (s[i][1]-'A')*26+ (s[i][3]-'A');
pairu[u].pb(d);
paird[d].pb(u);
pairl[l].pb(r);
pairr[r].pb(l);
ada[hsh(s[i])]=1;
}
for(int i =0;i<26*26;i++){
satu+= pairu[i].size()*paird[i].size();
memset(tmp1,0,sizeof(tmp1));
memset(tmp2,0,sizeof(tmp2));
memset(tmp3,0,sizeof(tmp3));
memset(tmp4,0,sizeof(tmp4));
for(auto j :pairu[i])tmp1[j]=1;
for(auto j :paird[i])tmp2[j]=1;
if(tmp1[i]&&tmp2[i])satu--;
satu+= pairl[i].size()*pairr[i].size();
for(auto j :pairl[i])tmp3[j]=1;
for(auto j :pairr[i])tmp4[j]=1;
if(tmp3[i]&&tmp4[i])satu--;
}
// cout<<satu<<endl;
for(int i =1;i<=n;i++){
abaw="";
ts(abaw,s[i][2],s[i][3],s[i][0],s[i][1]);
// cout<<abaw<<endl;
kaki="";
ts(kaki,s[i][1],s[i][0],s[i][3],s[i][2]);
if(s[i]!=abaw&&ada[hsh(abaw)])dua++;
if(s[i]!=kaki&&ada[hsh(kaki)])dua++;
if(s[i][0]==s[i][3]&&s[i][2]==s[i][1]){
tms = "";
ts(tms, s[i][1],s[i][0],s[i][3],s[i][2]);
if(s[i]!=tms&&ada[hsh(tms)])empat++;
}
if(s[i][1]==s[i][2]){
for(char j = 'A' ;j<='Z';j++){
tms1="";
ts(tms1,j,s[i][0],s[i][0],s[i][1]);
tms2 = "";
ts(tms2,s[i][1],s[i][3],s[i][3],j);
if(s[i]!=tms1&&ada[hsh(tms1)])dua++;
if(s[i]!=tms2&&ada[hsh(tms2)])dua++;
}
}
if(s[i][0]==s[i][3]){
for(char j = 'A' ;j<='Z';j++){
tms1 ="";
ts(tms1,s[i][1],j,s[i][0],s[i][1]);
tms2 = "";
ts(tms2,s[i][2],s[i][0],j,s[i][2]);
if(s[i]!=tms1&&ada[hsh(tms1)])dua++;
if(s[i]!=tms2&&ada[hsh(tms2)])dua++;
}
}
}
// cout<<dua<<' '<<empat<<endl;
cout<<satu- dua/2 + (empat/2)*3<<endl;
}
Compilation message
korteles.cpp: In function 'int main()':
korteles.cpp:23:11: warning: left operand of comma operator has no effect [-Wunused-value]
a,b;
^
korteles.cpp:23:12: warning: right operand of comma operator has no effect [-Wunused-value]
a,b;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
57592 KB |
Output is correct |
2 |
Correct |
35 ms |
57600 KB |
Output is correct |
3 |
Correct |
35 ms |
57728 KB |
Output is correct |
4 |
Correct |
36 ms |
57728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
57600 KB |
Output is correct |
2 |
Correct |
42 ms |
58108 KB |
Output is correct |
3 |
Correct |
37 ms |
57720 KB |
Output is correct |
4 |
Correct |
39 ms |
58112 KB |
Output is correct |
5 |
Correct |
39 ms |
58112 KB |
Output is correct |
6 |
Correct |
41 ms |
58232 KB |
Output is correct |
7 |
Correct |
40 ms |
57592 KB |
Output is correct |
8 |
Correct |
41 ms |
57592 KB |
Output is correct |
9 |
Correct |
35 ms |
57600 KB |
Output is correct |
10 |
Correct |
35 ms |
57728 KB |
Output is correct |
11 |
Correct |
36 ms |
57728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
489 ms |
69908 KB |
Output is correct |
2 |
Correct |
488 ms |
69836 KB |
Output is correct |
3 |
Correct |
484 ms |
70176 KB |
Output is correct |
4 |
Correct |
482 ms |
70136 KB |
Output is correct |
5 |
Correct |
484 ms |
70012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
57592 KB |
Output is correct |
2 |
Correct |
83 ms |
59512 KB |
Output is correct |
3 |
Correct |
283 ms |
63736 KB |
Output is correct |
4 |
Correct |
185 ms |
63480 KB |
Output is correct |
5 |
Correct |
193 ms |
63480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
57600 KB |
Output is correct |
2 |
Correct |
42 ms |
58108 KB |
Output is correct |
3 |
Correct |
37 ms |
57720 KB |
Output is correct |
4 |
Correct |
39 ms |
58112 KB |
Output is correct |
5 |
Correct |
39 ms |
58112 KB |
Output is correct |
6 |
Correct |
41 ms |
58232 KB |
Output is correct |
7 |
Correct |
40 ms |
57592 KB |
Output is correct |
8 |
Correct |
41 ms |
57592 KB |
Output is correct |
9 |
Correct |
35 ms |
57600 KB |
Output is correct |
10 |
Correct |
35 ms |
57728 KB |
Output is correct |
11 |
Correct |
36 ms |
57728 KB |
Output is correct |
12 |
Correct |
489 ms |
69908 KB |
Output is correct |
13 |
Correct |
488 ms |
69836 KB |
Output is correct |
14 |
Correct |
484 ms |
70176 KB |
Output is correct |
15 |
Correct |
482 ms |
70136 KB |
Output is correct |
16 |
Correct |
484 ms |
70012 KB |
Output is correct |
17 |
Correct |
83 ms |
59512 KB |
Output is correct |
18 |
Correct |
283 ms |
63736 KB |
Output is correct |
19 |
Correct |
185 ms |
63480 KB |
Output is correct |
20 |
Correct |
193 ms |
63480 KB |
Output is correct |
21 |
Correct |
193 ms |
60920 KB |
Output is correct |
22 |
Correct |
397 ms |
68364 KB |
Output is correct |
23 |
Correct |
278 ms |
64120 KB |
Output is correct |
24 |
Correct |
276 ms |
63992 KB |
Output is correct |