154402025-02-19 16:14:11PappMatyasParti (75 pont)cpp17Wrong answer 72/7572ms1980 KiB
#include <iostream>

using namespace std;

void Reduce(int A[],int B[], int x, int& tot, bool K[])
{
    K[x] = true;
    B[A[x]] --;
    B[A[x+1]] --;
    if(B[A[x]] < 2 && !K[2*(A[x] - 1)])
    {
        Reduce(A, B,  2*(A[x] - 1), tot, K);
        tot--;
    }
    if(B[A[x+1]] < 2 && !K[2*(A[x+1] - 1)])
    {
        Reduce(A, B, 2*(A[x+1] - 1), tot, K);
        tot--;
    }
}

int main()
{
    int n, A[200000], B[100001], tot, test = 0;
    bool K[200000];
    cin >> n;
    for(int i = 0; i < 2 * n; i++)
    {
        K[i] = false;
        cin >> A[i];
        B[A[i]] ++;
    }
    tot = n;
    for(int i = 1; i <= n; i++)
    {
        if(B[i] < 2 && !K[2*(i-1)])
        {
            Reduce(A, B, 2*(i-1), tot, K);
            tot--;
        }
    }
    for(int i = 1; i <= n; i ++)
    {
        if(B[i] >= 2)
        {
            test++;
        }
    }
    if(test > 2)
    {
        cout << test << endl;
        for(int i = 1; i <= n; i ++)
        {
            if(B[i] >= 2)
            {
                cout << i << " ";
            }
        }
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/01ms508 KiB
2Accepted0/035ms1076 KiB
3Accepted3/31ms512 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms512 KiB
9Accepted4/41ms316 KiB
10Accepted4/42ms316 KiB
11Accepted4/41ms316 KiB
12Accepted4/42ms316 KiB
13Accepted4/43ms316 KiB
14Accepted4/43ms316 KiB
15Accepted4/435ms1020 KiB
16Accepted4/443ms1372 KiB
17Accepted4/450ms1416 KiB
18Accepted4/457ms1684 KiB
19Accepted4/465ms1688 KiB
20Accepted4/471ms1980 KiB
21Accepted4/472ms1916 KiB
22Accepted4/41ms316 KiB