Submission details
Task:Kolmijako
Sender:sharph2
Submission time:2025-09-05 18:35:46 +0300
Language:C++ (C++17)
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED23
#2ACCEPTED42
#3ACCEPTED35
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3details
#2ACCEPTED0.01 s2, 3details
#3ACCEPTED0.01 s3details

Code

#include <array>
#include <cmath>
#include <iostream>
#include <optional>
#include <vector>

using namespace std;

optional<array<vector<int>, 3>> ratko(int n) {
    int sum = n * (n + 1) / 2;
    if(sum % 3 != 0) {
        return nullopt;
    }

    array<vector<int>, 3> ratk;

    int i = 0;
    if(n % 6 == 0) {
    } else if(n % 6 == 2) {
        if(n < 8) return nullopt;
        ratk[0].push_back(8);
        ratk[0].push_back(4);
        ratk[1].push_back(2);
        ratk[1].push_back(3);
        ratk[1].push_back(7);
        ratk[2].push_back(1);
        ratk[2].push_back(5);
        ratk[2].push_back(6);
        i = 8;
    } else if(n % 6 == 3) {
        if(n < 9) return nullopt;
        ratk[0].push_back(1);
        ratk[0].push_back(5);
        ratk[0].push_back(9);
        ratk[1].push_back(3);
        ratk[1].push_back(4);
        ratk[1].push_back(8);
        ratk[2].push_back(2);
        ratk[2].push_back(6);
        ratk[2].push_back(7);
        i = 9;
    } else if(n % 6 == 5) {
        ratk[0].push_back(1);
        ratk[0].push_back(4);
        ratk[1].push_back(2);
        ratk[1].push_back(3);
        ratk[2].push_back(5);
        i = 5;
    } else {
        throw 5;
    }

    for(; i < n; i += 6) {
        ratk[0].push_back(i + 1);
        ratk[1].push_back(i + 2);
        ratk[2].push_back(i + 3);
        ratk[2].push_back(i + 4);
        ratk[1].push_back(i + 5);
        ratk[0].push_back(i + 6);
    }
    if(i != n) throw 5;
    return ratk;
}

void validoi(int n, array<vector<int>, 3>& ratk) {
    int sum = n * (n + 1) / 2;
    if(sum % 3 != 0) {
        throw 5;
    }
    sum /= 3;

    vector<bool> seen(n + 1);
    for(vector<int>& osa : ratk) {
        int sum2 = 0;
        for(int luku : osa) {
            if(luku <= 0 || luku > n || seen[luku]) throw 5;
            seen[luku] = true;
            sum2 += luku;
        }
        if(sum2 != sum) throw 5;
    }
    for(int i = 1; i <= n; ++i) {
        if(!seen[i]) throw 5;
    }
}

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

    // for(int n = 1; n <= 1000; ++n) {
    //     auto ratk = ratko(n);
    //     if(ratk.has_value()) {
    //         validoi(n, ratk.value());
    //     }
    // }

    int tc;
    cin >> tc;

    cout.precision(20);

    for(int ti = 0; ti < tc; ++ti) {
        int n;
        cin >> n;

        auto ratk = ratko(n);
        if(ratk.has_value()) {
            cout << "YES\n";
            for(vector<int>& osa : ratk.value()) {
                cout << osa.size() << "\n";
                for(int luku : osa) {
                    cout << luku << " ";
                }
                cout << "\n";
            }
        } else {
            cout << "NO\n";
        }
    }

    return 0;
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
15
1
2
3
4
...

correct output
NO
NO
NO
NO
YES
...

user output
NO
NO
NO
NO
YES
...
Truncated

Test 2

Group: 2, 3

Verdict: ACCEPTED

input
100
1
2
3
4
...

correct output
NO
NO
NO
NO
YES
...

user output
NO
NO
NO
NO
YES
...
Truncated

Test 3

Group: 3

Verdict: ACCEPTED

input
100
564
895
546
980
...

correct output
YES
188
1 6 12 7 18 13 24 19 30 25 36 ...

user output
YES
188
1 6 7 12 13 18 19 24 25 30 31 ...
Truncated