Submission #152886

# Submission time Handle Problem Language Result Execution time Memory
152886 2019-09-10T11:21:20 Z 2qbingxuan FunctionCup Museum (FXCUP4_museum) C++17
0 / 100
2 ms 376 KB
#include <algorithm>
#include <vector>

using namespace std;
typedef int64_t ll;

int64_t check2(vector<int> &A,vector<int> &B) {
    int n = A.size();
    vector<int> v(n);
    ll res = 0;
    for(int i = 0; i < n; i++) v[i] = A[i]*200+B[i];
    sort(v.begin(),v.end());
    for(int i = 0,j; i < n; i = j) {
        for(j = i; j < n; j++) if(v[i]!=v[j]) break;
        res += (j-i)*(j-i-1)/2;
    }
    return res;
}
int64_t check3(vector<int> &A,vector<int> &B,vector<int> &C) {
    int n = A.size();
    vector<int> v(n);
    ll res = 0;
    for(int i = 0; i < n; i++) v[i] = A[i]*40000+B[i]*200+C[i];
    sort(v.begin(),v.end());
    for(int i = 0,j; i < n; i = j) {
        for(j = i; j < n; j++) if(v[i]!=v[j]) break;
        res += (j-i)*(j-i-1)/2;
    }
    return res;
}

int64_t CountSimilarPairs(vector<int> A,vector<int> B,vector<int> C) {
    int n = A.size();
    ll res = 0;
    // AB, BC, CA, 2ABC
    res += check2(A,B);
    res += check2(B,C);
    res += check2(C,A);
    res -= check3(A,B,C)*2;
    return res;
}

Compilation message

museum.cpp: In function 'int64_t CountSimilarPairs(std::vector<int>, std::vector<int>, std::vector<int>)':
museum.cpp:33:9: warning: unused variable 'n' [-Wunused-variable]
     int n = A.size();
         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -