This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
#define all(x) (x).begin(), (x).end()
#define le(vec) vec[vec.size()-1]
#define sz(x) ((int)((x).size()))
#define pb push_back
#define s second
#define f first
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e13;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
const int N=5e5+10;
int n;
ll ans;
char g[N][2][2];
map<vector<char>, int> Up, Left, Right, Down, LU, UR, RD, DL, all;
int main()
{
setIO();
cin >> n;
FOR(i, 0, n)
{
FOR(j, 0, 2)
{
FOR(k, 0, 2)
{
cin >> g[i][j][k];
}
}
}
FOR(i, 0, n)
{
char a=g[i][0][0], b=g[i][0][1], c=g[i][1][0], d=g[i][1][1];
ans+=Up[{c,d}];
ans+=Right[{a,c}];
ans+=Down[{a,b}];
ans+=Left[{b,d}];
if(a==d){
ans-=UR[{c,a,c}];
ans-=DL[{b,a,b}];
}
if(b==c){
ans-=LU[{d,b,d}];
ans-=RD[{a,b,a}];
}
if(a==d && b==c){
ans+=all[{b,a,a,b}];
}
Up[{a,b}]++;
Right[{b,d}]++;
Down[{c,d}]++;
Left[{a,c}]++;
LU[{c,a,b}]++;
UR[{a,b,d}]++;
RD[{b,d,c}]++;
DL[{d,c,a}]++;
all[{a,b,c,d}]++;
}
cout << ans;
}
Compilation message (stderr)
korteles.cpp: In function 'void setIO(std::string)':
korteles.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
korteles.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |