답안 #151009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151009 2019-09-01T14:44:20 Z joylintp 함수컵 박물관 (FXCUP4_museum) C++17
100 / 100
235 ms 8936 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 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 4 ms 400 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 4 ms 400 KB Output is correct
8 Correct 4 ms 376 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 4 ms 376 KB Output is correct
11 Correct 9 ms 632 KB Output is correct
12 Correct 25 ms 1568 KB Output is correct
13 Correct 65 ms 2540 KB Output is correct
14 Correct 96 ms 4204 KB Output is correct
15 Correct 145 ms 5204 KB Output is correct
16 Correct 142 ms 8928 KB Output is correct
17 Correct 184 ms 8932 KB Output is correct
18 Correct 221 ms 8936 KB Output is correct
19 Correct 235 ms 8928 KB Output is correct
20 Correct 235 ms 8864 KB Output is correct