QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#613#368986#8217. King's Dinnerucup-team1087ucup-team3215Failed.2024-05-04 17:10:482024-05-04 17:10:49

Details

Extra Test:

Invalid Input

input:

1
114514

output:


result:

FAIL Integer parameter [name=n] equals to 114514, violates the range [1, 100] (test case 1, stdin, line 2)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368986#8217. King's Dinnerucup-team3215#AC ✓1ms3604kbC++202.1kb2024-03-27 18:49:272024-03-27 18:49:28

answer

#include <bits/stdc++.h>

using namespace std;

void put(vector<string> & g, int i, int j, int sh, int n = 0) {
    g[sh + i][sh + j] = '#';
    if (n) {
        put(g, n - 1 - j, i, sh, 0);
    }
}

void sol(vector<string> & g, int n, int sh) {
    if (n < 2) {
        return;
    }
    if (n == 3) {
        put(g, 0, 0, sh);
        put(g, 1, 0, sh);
        put(g, 0, 2, sh);
        put(g, 1, 2, sh);
    } else if (n % 3 == 2) {
        if (n % 2 == 0) {
            for (int i = 0; i < n; i += 3) {
                for (int j = 0; j < n - 3; j += 2) {
                    put(g, j, i, sh);
                    put(g, j, i + 1, sh);
                }
            }
            for (int i = 0; i < n; i += 2) {
                put(g, n - 1, i, sh);
                put(g, n - 2, i, sh);
            }
        } else {
            for (int i = 0; i < n; i += 3) {
                for (int j = 0; j < n; j += 2) {
                    put(g, j, i, sh);
                    put(g, j, i + 1, sh);
                }
            }
        }
    } else if (n % 3 == 1) {
        for (int i = 0; i < n - 3; i += 3) {
            put(g, i, 0, sh, n);
            put(g, i + 1, 0, sh, n);
            put(g, n - 1 - (i), n - 1, sh, n);
            put(g, n - 1 - (i + 1), n - 1, sh, n);
        }
        sol(g, n - 4, sh + 2);
    } else {
        for (int i = 0; i < n - 3; i += 3) {
            put(g, i, 0, sh, n);
            put(g, i + 1, 0, sh, n);
            put(g, i, 2, sh, n);
            put(g, i + 1, 2, sh, n);

            put(g, n - 1 - (i), n - 1, sh, n);
            put(g, n - 1 - (i + 1), n - 1, sh, n);
            put(g, n - 1 - (i), n - 3, sh, n);
            put(g, n - 1 - (i + 1), n - 3, sh, n);
        }
        sol(g, n - 8, sh + 4);
    }
}

void solve() {
    int n;
    cin >> n;
    vector<string> g(n, string(n, '.'));
    sol(g, n, 0);
    for (const string & s : g) {
        cout << s << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}