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 <iostream>
#include <vector>
using namespace std;
int n, k;
int pow3[10];
int inv(int a, int b)
{
int c = 0;
for(int j = 0; j < k; j++)
{
c += pow3[j] * ((9 - (a % 3) - (b % 3)) % 3);
a /= 3;
b /= 3;
}
return c;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
pow3[0] = 1;
for(int e = 1; e < 10; e++)
pow3[e] = 3 * pow3[e-1];
int num[n];
for(int i = 0; i < n; i++)
{
num[i] = 0;
string s;
cin >> s;
for(int j = 0; j < k; j++)
{
num[i] += pow3[j] * (s[j] - '1');
}
// cerr << i << ' ' << num[i] << '\n';
}
vector<int> exists(2500, 0);
int ans = 0;
for(int i = 0; i < n; i++)
{
for(int j = i+1; j < n; j++)
{
ans += exists[inv(num[i], num[j])];
}
exists[ num[i] ] = 1;
}
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |