답안 #149977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
149977 2019-09-01T07:29:31 Z HSNU(#3687, joylintp, 147, wiwiho) 함수컵 박물관 (FXCUP4_museum) C++17
100 / 100
258 ms 8992 KB
#include<bits/stdc++.h>
#include "museum.h"

using namespace std;

struct vis
{
    int b, t, g;
};

bool cmp1(vis a, vis b)
{
    if (a.b < b.b)
        return true;
    else
        return false;
}

bool cmp2(vis a, vis b)
{
    if (a.t < b.t)
        return true;
    else
        return false;
}

bool cmp3(vis a, vis b)
{
    if (a.g < b.g)
        return true;
    else
        return false;
}

bool cmp4(vis a, vis b)
{
    if (a.b < b.b)
        return true;
    else if (a.b > b.b)
        return false;
    else if (a.t < b.t)
        return true;
    else
        return false;
}

bool cmp5(vis a, vis b)
{
    if (a.g < b.g)
        return true;
    else if (a.g > b.g)
        return false;
    else if (a.t < b.t)
        return true;
    else
        return false;
}

bool cmp6(vis a, vis b)
{
    if (a.g < b.g)
        return true;
    else if (a.g > b.g)
        return false;
    else if (a.b < b.b)
        return true;
    else
        return false;
}

bool cmp7(vis a, vis b)
{
    if (a.g < b.g)
        return true;
    else if (a.g > b.g)
        return false;
    else if (a.b < b.b)
        return true;
    else if (a.b > b.b)
        return false;
    else if (a.t < b.t)
        return true;
    else
        return false;
}

long long CountSimilarPairs(vector<int> B, vector<int> T, vector<int> G)
{
	long long N = B.size(), cnt = 0;

    vector<vis> v;
    for (int i = 0; i < N; i++)
        v.push_back({B[i], T[i], G[i]});

    sort(v.begin(), v.end(), cmp1);
    for (int i = 0; i < N; )
    {
        int j = i;
        while (j < N && v[i].b == v[j].b)
            j++;

        long long t = j - i;
        cnt += t * (t - 1) / 2;
        i = j;
    }

    sort(v.begin(), v.end(), cmp2);
    for (int i = 0; i < N; )
    {
        int j = i;
        while (j < N && v[i].t == v[j].t)
            j++;

        long long t = j - i;
        cnt += t * (t - 1) / 2;
        i = j;
    }

    sort(v.begin(), v.end(), cmp3);
    for (int i = 0; i < N; )
    {
        int j = i;
        while (j < N && v[i].g == v[j].g)
            j++;

        long long t = j - i;
        cnt += t * (t - 1) / 2;
        i = j;
    }

    sort(v.begin(), v.end(), cmp4);
    for (int i = 0; i < N; )
    {
        int j = i;
        while (j < N && v[i].b == v[j].b && v[i].t == v[j].t)
            j++;

        long long t = j - i;
        cnt -= t * (t - 1) / 2;
        i = j;
    }

    sort(v.begin(), v.end(), cmp5);
    for (int i = 0; i < N; )
    {
        int j = i;
        while (j < N && v[i].g == v[j].g && v[i].t == v[j].t)
            j++;

        long long t = j - i;
        cnt -= t * (t - 1) / 2;
        i = j;
    }

    sort(v.begin(), v.end(), cmp6);
    for (int i = 0; i < N; )
    {
        int j = i;
        while (j < N && v[i].g == v[j].g && v[i].b == v[j].b)
            j++;

        long long t = j - i;
        cnt -= t * (t - 1) / 2;
        i = j;
    }

    sort(v.begin(), v.end(), cmp7);
    for (int i = 0; i < N; )
    {
        int j = i;
        while (j < N && v[i].g == v[j].g && v[i].b == v[j].b && v[i].t == v[j].t)
            j++;

        long long t = j - i;
        cnt += t * (t - 1) / 2;
        i = j;
    }

	return cnt;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 7 ms 432 KB Output is correct
7 Correct 8 ms 380 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 9 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 7 ms 432 KB Output is correct
7 Correct 8 ms 380 KB Output is correct
8 Correct 7 ms 512 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 9 ms 512 KB Output is correct
11 Correct 11 ms 640 KB Output is correct
12 Correct 31 ms 1660 KB Output is correct
13 Correct 70 ms 2544 KB Output is correct
14 Correct 103 ms 4204 KB Output is correct
15 Correct 158 ms 5228 KB Output is correct
16 Correct 146 ms 8992 KB Output is correct
17 Correct 196 ms 8984 KB Output is correct
18 Correct 234 ms 8932 KB Output is correct
19 Correct 242 ms 8984 KB Output is correct
20 Correct 258 ms 8932 KB Output is correct