QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#403442#7740. Puzzle: Question MarkGodwangWA 212ms6236kbC++146.2kb2024-05-02 13:11:592024-05-02 13:11:59

Judging History

你现在查看的是最新测评结果

  • [2024-05-02 13:11:59]
  • 评测
  • 测评结果:WA
  • 用时:212ms
  • 内存:6236kb
  • [2024-05-02 13:11:59]
  • 提交

answer

#include <iostream>
using namespace std;
#include <set>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdio>
#include <string>
#include <cstring>
#include <string.h>
#include <stdlib.h>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <stack>
#include <queue>
#include <ctype.h>
#include <vector>
#include <random>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = n; i >= a; i--)
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define endl '\n'
const double pai = acos(-1);
ll extend_gcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extend_gcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
ll fastpow(ll a, ll n, ll mod)
{
    ll ans = 1;
    a %= mod;
    while (n)
    {
        if (n & 1)
            ans = (ans * a)%mod; //% mod
        a = (a * a)%mod;         //% mod
        n >>= 1;
    }
    return ans;
}
int dir[4][2] =
    {
        {0, 1}, {0, -1}, {1, 0}, {-1, 0}}; // d a w s

const double inf = 1000000000000000000;
const ll mod = 1e9 + 7, P1 = 13331;
const double eps = 1e-7;
const int N = 2e3 + 10, M = 1e6 + 10;

int t,n;
int a[N][N];
int cnt;

void solve24(int hang,int lie)
{
    a[hang][lie]=a[hang+1][lie]=a[hang][lie+1]=a[hang+1][lie+2]=++cnt;
    a[hang+1][lie+1]=a[hang][lie+2]=a[hang][lie+3]=a[hang+1][lie+3]=++cnt;
}
void solve42(int hang,int lie)
{
    a[hang][lie]=a[hang][lie+1]=a[hang+1][lie+1]=a[hang+2][lie]=++cnt;
    a[hang+1][lie]=a[hang+2][lie+1]=a[hang+3][lie]=a[hang+3][lie+1]=++cnt;
}

void solve3311(int hang,int lie)
{
    a[hang+1][lie]=a[hang+1][lie+1]=a[hang+2][lie]=a[hang+2][lie+2]=++cnt;
    a[hang][lie+1]=a[hang][lie+2]=a[hang+1][lie+2]=a[hang+2][lie+1]=++cnt;
}

void solve3313(int hang,int lie)
{
    a[hang][lie]=a[hang][lie+1]=a[hang+1][lie]=a[hang+2][lie+1]=++cnt;
    a[hang+1][lie+1]=a[hang+1][lie+2]=a[hang+2][lie]=a[hang+2][lie+2]=++cnt;
}

void solve3331(int hang,int lie)
{
    a[hang][lie]=a[hang][lie+1]=a[hang+1][lie]=a[hang+1][lie+2]=++cnt;
    a[hang][lie+2]=a[hang+1][lie+1]=a[hang+2][lie+1]=a[hang+2][lie+2]=++cnt;
}

void solve3333(int hang,int lie)
{
    a[hang][lie]=a[hang+1][lie+1]=a[hang+2][lie]=a[hang+2][lie+1]=++cnt;
    a[hang+1][lie]=a[hang][lie+1]=a[hang][lie+2]=a[hang+1][lie+2]=++cnt;
}

void solve5(int hang,int lie)
{
    solve24(hang,lie);
    solve3313(hang+2,lie);
    a[hang+2][lie+3]=a[hang+3][lie+4]=a[hang+4][lie+3]=a[hang+4][lie+4]=++cnt;
}

void solve7(int hang,int lie)
{
    solve3333(hang,lie);
    solve24(hang+3,lie);
    solve24(hang+5,lie);
    solve42(hang,lie+5);
    solve3311(hang+4,lie+4);
    a[hang][lie+3]=a[hang+1][lie+4]=a[hang+2][lie+3]=a[hang+2][lie+4]=++cnt;
}

void te(int hang,int lie)
{
    a[hang][lie]=a[hang][lie+1]=a[hang+1][lie]=a[hang+1][lie+2]=++cnt;
    a[hang+1][lie+1]=a[hang+1][lie+3]=a[hang+2][lie+2]=a[hang+2][lie+3]=++cnt;
}

void solve9(int hang,int lie)
{
    te(hang+2,lie+3);
    te(hang+4,lie+2);
    solve24(hang,lie);
    solve24(hang+7,lie+5);
    solve42(hang,lie+7);
    solve42(hang+5,lie);
    solve3331(hang,lie+4);
    solve3333(hang+2,lie);
    solve3313(hang+6,lie+2);
    solve3311(hang+4,lie+6);
}

void solve(int hang,int lie)
{
    if(n<=9)
    {
        solve9(hang,lie);
        return;
    }
    for(int j=1;j+3<=n/4*4;j+=4)
    {
        solve24(hang,j);
        solve24(hang+n-2,j);
    }
    //huang
    a[1][n-4]=a[1][n-3]=a[2][n-4]=a[3][n-3]=++cnt;
    a[2][n-3]=a[3][n-2]=a[4][n-3]=a[4][n-2]=++cnt;
    
    a[hang+n-6][n-1]=a[hang+n-6][n]=a[hang+n-5][n-2]=a[hang+n-5][n]=++cnt;
    a[hang+n-5][n-3]=a[hang+n-5][n-1]=a[hang+n-4][n-3]=a[hang+n-4][n-2]=++cnt;

    //lv
    solve3311(hang+n-3,n-4);
    solve3331(1,n-2);

    //youxia
    solve42(hang+n-4,n-1);
    for(int i=hang+3;  i+3<=hang+n-7   ;i+=4)
    {
        solve42(i,n-1);
        solve42(i+1,n-3);
    }


    n-=4;
    solve(hang+2,1);
}


int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("ain.txt", "r", stdin);freopen("aout.txt", "w", stdout);
    cin>>t;
    while(t--)
    {
        cnt=0;
        cin>>n;
        int tem=n;
        rep(i,1,n)
        {
            rep(j,1,n)
            {
                a[i][j]=0;
            }

        }
        if(n%4==0)
        {
            for(int i=1;i<=n;i+=2)
            {
                for(int j=1;j<=n;j+=4)
                {
                    solve24(i,j);
                }

            }
        }
        else if(n%2==0)
        {
           
            for(int i=1;i<=n;i+=2)
            {
                for(int j=1;j+3<=n;j+=4)
                {
                    solve24(i,j);
                }

            }
            for(int i=1;i+3<=n;i+=4)
            {
                solve42(i,n-1);
            }
        }
        else
        {
            if(n==1)
            {

            }
            else if(n==3)
            {
                solve3333(1,1);
            }
            else if(n==5)
            {
                solve5(1,1);
            }
            else if(n==7)
            {
                solve7(1,1);
            }
            else if(n==9)
            {
                solve9(1,1);
            }
            else
            {
                if(n%4==3)
                {
                    int k=n/4;
                    solve3311(1+4*k,1+4*k);
                    for(int j=1;j<=4*k;j+=4)
                    {
                        solve24(4*k+2,j);
                    }
                    for(int i=1;i<=4*k;i+=4)
                    {
                        solve42(i,4*k+2);
                    }
                    n-=2;
                }
                solve(1,1);
                
            }
        }
        cout<<cnt<<endl;
        rep(i,1,tem)
        {
            rep(j,1,tem)
            {
                if(j>1)
                {
                    cout<<" ";
                }
                cout<<a[i][j];
            }
            cout<<endl;
        }
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

2
3
4

output:

2
1 2 2
2 1 2
1 1 0
4
1 1 2 2
1 2 1 2
3 3 4 4
3 4 3 4

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 212ms
memory: 6236kb

input:

246
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...

output:

0
0
0
0 0
0 0
2
1 2 2
2 1 2
1 1 0
4
1 1 2 2
1 2 1 2
3 3 4 4
3 4 3 4
5
1 1 2 2 0
1 2 1 2 0
3 3 0 5 0
3 4 4 0 5
4 3 4 5 5
8
1 1 2 2 7 7
1 2 1 2 8 7
3 3 4 4 7 8
3 4 3 4 8 8
5 5 6 6 0 0
5 6 5 6 0 0
11
1 2 2 11 0 7 7
2 1 2 0 11 8 7
1 1 0 11 11 7 8
3 3 4 4 0 8 8
3 4 3 4 0 10 10
5 5 6 6 9 9 10
5 6 5 6 9 10...

result:

wrong answer Integer parameter [name=num] equals to 46, violates the range [0, 42] (test case 13)