154462025-02-19 16:33:37PappMatyasParti (75 pont)cpp17Wrong answer 72/7574ms1920 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], total;
    bool K[200000];
    cin >> n;
    for(int i = 0; i < 2 * n; i++)
    {
        K[i] = false;
        cin >> A[i];
        B[A[i]] ++;
    }
    total = n;
    for(int i = 1; i <= n; i++)
    {
        if(B[i] < 2 && !K[2*(i-1)])
        {
            Reduce(A, B, 2*(i-1), total, K);
            total--;
        }
    }
    cout << total << endl;
    for(int i = 0; i < 2 * n; i +=2)
    {
        if(!K[i])
        {
            cout << (i+2)/2 << " ";
        }
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base72/75
1Accepted0/01ms316 KiB
2Accepted0/037ms1076 KiB
3Accepted3/31ms316 KiB
4Accepted3/31ms508 KiB
5Wrong answer0/31ms316 KiB
6Accepted3/31ms316 KiB
7Accepted3/31ms316 KiB
8Accepted4/41ms316 KiB
9Accepted4/41ms316 KiB
10Accepted4/42ms556 KiB
11Accepted4/42ms316 KiB
12Accepted4/42ms316 KiB
13Accepted4/43ms448 KiB
14Accepted4/43ms316 KiB
15Accepted4/437ms1188 KiB
16Accepted4/445ms1168 KiB
17Accepted4/452ms1372 KiB
18Accepted4/459ms1588 KiB
19Accepted4/467ms1712 KiB
20Accepted4/474ms1920 KiB
21Accepted4/474ms1844 KiB
22Accepted4/41ms316 KiB