제출 #491624

#제출 시각아이디문제언어결과실행 시간메모리
491624blueSet (COCI21_set)C++17
40 / 110
58 ms460 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...