QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#403441 | #7740. Puzzle: Question Mark | Godwang | WA | 0ms | 3652kb | C++14 | 6.2kb | 2024-05-02 13:08:47 | 2024-05-02 13:08:48 |
Judging History
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);
}
}
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: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
2 3 4
output:
1 2 2 2 1 2 1 1 0 1 1 2 2 1 2 1 2 3 3 4 4 3 4 3 4
result:
wrong answer Integer parameter [name=a_ij] equals to 2, violates the range [0, 1] (test case 1)