154202025-02-19 13:32:02PappMatyasParti (75 pont)cpp17Wrong answer 68/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[100000], tot;
    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--;
        }
    }
    cout << tot << endl;
    for(int i = 1; i <= n; i ++)
    {
        if(B[i] >= 2)
        {
            cout << i << " ";
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base68/75
1Accepted0/01ms316 KiB
2Accepted0/035ms1076 KiB
3Accepted3/31ms508 KiB
4Accepted3/31ms316 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms316 KiB
10Accepted4/42ms328 KiB
11Accepted4/42ms424 KiB
12Accepted4/42ms500 KiB
13Accepted4/43ms316 KiB
14Accepted4/43ms316 KiB
15Accepted4/435ms1208 KiB
16Accepted4/443ms1356 KiB
17Accepted4/450ms1440 KiB
18Accepted4/457ms1532 KiB
19Accepted4/467ms1720 KiB
20Wrong answer0/472ms1980 KiB
21Accepted4/472ms1936 KiB
22Accepted4/41ms316 KiB