154332025-02-19 15:59:23PappMatyasParti (75 pont)cpp17Wrong answer 72/7575ms1844 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;
    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--;
        }
    }
    if(tot > 2)
    {
        cout << tot << endl;
        for(int i = 1; i <= n; i ++)
        {
            if(B[i] >= 2)
            {
                cout << i << " ";
            }
        }
    }
    else
    {
        cout << 0 << endl;
    }
    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/42ms508 KiB
10Accepted4/42ms424 KiB
11Accepted4/41ms316 KiB
12Accepted4/42ms316 KiB
13Accepted4/43ms316 KiB
14Accepted4/44ms508 KiB
15Accepted4/437ms1052 KiB
16Accepted4/445ms1212 KiB
17Accepted4/454ms1332 KiB
18Accepted4/461ms1472 KiB
19Accepted4/471ms1844 KiB
20Accepted4/475ms1844 KiB
21Accepted4/475ms1796 KiB
22Accepted4/41ms316 KiB