제출 #1271822

#제출 시각아이디문제언어결과실행 시간메모리
1271822chanhchuong123Lampice (COCI21_lampice)C++20
50 / 50
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

const int MAX = 1010;
int n, k;
int a[MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> k;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }

    for (int i = 1; k * i <= n; ++i)
    {
        for (int st = 1, en = k * i; en <= n; ++st, ++en)
        {
            bool flag = true;
            for (int lf = st; lf <= en; lf += i)
            {
                for (int j = 0; j < i; ++j)
                {
                    // cout << st + j << ' ' << lf + j << '\n';
                    if (a[st + j] != a[lf + j])
                    {
                        flag = false;
                        break;
                    }
                }
            }
            if (flag)
            {
                cout << i << '\n';
                for (int j = 0; j < i; ++j)
                {
                    cout << a[st + j] << ' ';
                }
                return 0;
            }
        }
    }
    cout << -1;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...