이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 1000006;
int n, m;
int c[N];
pair<int, int> a[N];
int ans[N];
void solvv()
{
    for (int x = 1; x <= m; ++x)
    {
        for (int y = 1; y <= m; ++y)
        {
            int yans = 0;
            for (int j = 1; j <= n; ++j)
            {
                if (a[j].fi == x || a[j].se == x)
                {
                    if (a[j].fi && a[j].fi != x)
                        ++yans;
                    if (a[j].se && a[j].se != x)
                        ++yans;
                    continue;
                }
                if (a[j].fi && a[j].fi != y)
                    ++yans;
                if (a[j].se && a[j].se != y)
                    ++yans;
            }
            ans[x] = min(ans[x], yans);
        }
    }
}
void solv()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> c[i];
    for (int i = 1; i <= m; ++i)
        ans[i] = n;
    if (n % 2 == 0)
    {
        for (int i = 1; i <= n; i += 2)
        {
            a[i / 2 + 1] = m_p(c[i], c[i + 1]);
        }
        n = n / 2;
        solvv();
        n *= 2;
        a[1] = m_p(c[1], 0);
        a[2] = m_p(c[n], 0);
        for (int i = 2; i < n; i += 2)
        {
            a[i / 2 + 2] = m_p(c[i], c[i + 1]);
        }
        n = 2 + (n - 2) / 2;
        solvv();
    }
    else
    {
        a[1] = m_p(c[1], 0);
        for (int i = 2; i <= n; i += 2)
            a[i / 2 + 1] = m_p(c[i], c[i + 1]);
        n = (n - 1) / 2 + 1;
        solvv();
        n = (n - 1) * 2 + 1;
        a[1] = m_p(c[n], 0);
        for (int i = 1; i < n; i += 2)
            a[i / 2 + 2] = m_p(c[i], c[i + 1]);
        solvv();
    }
    for (int i = 1; i <= m; ++i)
        cout << ans[i] << "\n";
}
int main()
{
    #ifdef SOMETHING
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #endif // SOMETHING
    ios_base::sync_with_stdio(false), cin.tie(0);
    int tt = 1;
    //cin >> tt;
    while (tt--)
    {
        solv();
    }
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |