QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#265116 | #7740. Puzzle: Question Mark | ucup-team266# | WA | 197ms | 6176kb | C++20 | 3.1kb | 2023-11-25 16:49:41 | 2023-11-25 16:49:41 |
Judging History
answer
/*
Things to notice:
1. do not calculate useless values
2. do not use similar names
Things to check:
1. submit the correct file
2. time (it is log^2 or log)
3. memory
4. prove your naive thoughts
5. long long
6. corner case like n=0,1,inf or n=m
7. check if there is a mistake in the ds or other tools you use
8. fileio in some oi-contest
9. module on time
10. the number of a same divisor in a math problem
11. multi-information and queries for dp and ds problems
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
const int mod=998244353;
const int inf=0x3f3f3f3f;
int n;
int ans[2005][2005],idx;
void fill1(int x1,int y1)
{
idx++;
ans[x1][y1]=ans[x1][y1+1]=ans[x1+1][y1]=ans[x1+1][y1+2]=idx;
idx++;
ans[x1+1][y1+1]=ans[x1][y1+2]=ans[x1][y1+3]=ans[x1+1][y1+3]=idx;
}
void fill2(int x1,int y1)
{
idx++;
ans[x1][y1]=ans[x1][y1+1]=ans[x1+1][y1]=ans[x1+2][y1+1]=idx;
idx++;
ans[x1+1][y1+1]=ans[x1+2][y1]=ans[x1+3][y1]=ans[x1+3][y1+1]=idx;
}
void print()
{
cout<<idx<<"\n";
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++) cout<<ans[i][j]<<(j==n?"\n":" ");
// for(int j=1;j<=n;j++) cout<<left<<setw(4)<<ans[i][j]<<" ";
// cout<<"\n";
}
}
int ans5[5][5]={
{0,4,4,0,0},
{5,4,5,3,3},
{5,5,4,3,0},
{1,1,2,2,3},
{1,2,1,2,0}
};
void solve()
{
cin>>n;
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans[i][j]=0;
idx=0;
if(n==1)
{
cout<<"0\n0\n";
return;
}
if(n==2)
{
cout<<"0\n0 0\n0 0\n";
return;
}
if(n==3)
{
cout<<"2\n0 1 1\n2 2 1\n2 1 2\n";
return;
}
if(n%2==0)
{
for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(i%2==1&&j%4==1&&i+1<=n&&j+3<=n) fill1(i,j);
if(n%4==2)
{
for(int i=1;i+3<=n;i+=4) fill1(n-1,i),fill2(i,n-1);
}
print();
return;
}
int flg=0;
if(n%4==3) flg=1,n-=2;
int st=(n+1)/2-2;
idx=5;
for(int i=0;i<5;i++) for(int j=0;j<5;j++) ans[st+i][1+j]=ans5[i][j];
for(int i=5,L=st,R=st+4;i<n;i+=4,L-=2,R+=2)
{
idx++;
int x=R,y=i;
ans[x+1][y]=ans[x+2][y]=ans[x+2][y+1]=ans[x+1][y+2]=idx;
idx++;
ans[x][y+1]=ans[x][y+2]=ans[x+1][y+1]=ans[x+2][y+2]=idx;
idx++;
x=L,y=i;
ans[x-2][y]=ans[x-2][y+1]=ans[x-1][y]=ans[x][y+1]=idx;
idx++;
ans[x-1][y+1]=ans[x][y+2]=ans[x+1][y+1]=ans[x+1][y+2]=idx;
idx++;
ans[x+3][y+1]=ans[x+3][y+2]=ans[x+2][y+1]=ans[x+2][y+3]=idx;
idx++;
ans[x+2][y+2]=ans[x+2][y+4]=ans[x+1][y+3]=ans[x+1][y+4]=idx;
idx++;
ans[x-2][y+2]=ans[x-2][y+3]=ans[x-1][y+2]=ans[x-1][y+4]=idx;
idx++;
ans[x-2][y+4]=ans[x-1][y+3]=ans[x][y+3]=ans[x][y+4]=idx;
for(int j=1;j<i;j+=4) fill1(L-2,j),fill1(R+1,j);
for(int j=L+4;ans[j][i+1]==0;j+=4) fill2(j,i+1);
for(int j=L+3;j<=R;j+=4) fill2(j,i+3);
}
if(flg)
{
for(int i=1;i<n;i+=4) fill1(n+1,i),fill2(i,n+1);
idx++;
ans[n+1][n]=ans[n+2][n]=ans[n+2][n+1]=ans[n+1][n+2]=idx;
idx++;
ans[n][n+1]=ans[n][n+2]=ans[n+1][n+1]=ans[n+2][n+2]=idx;
n+=2;
}
print();
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int _=1;
cin>>_;
while(_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3728kb
input:
2 3 4
output:
2 0 1 1 2 2 1 2 1 2 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: 197ms
memory: 6176kb
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 0 1 1 2 2 1 2 1 2 4 1 1 2 2 1 2 1 2 3 3 4 4 3 4 3 4 5 0 4 4 0 0 5 4 5 3 3 5 5 4 3 0 1 1 2 2 3 1 2 1 2 0 10 1 1 2 2 9 9 1 2 1 2 9 10 3 3 4 4 10 9 3 4 3 4 10 10 7 7 8 8 0 0 7 8 7 8 0 0 11 0 4 4 0 0 8 8 5 4 5 3 3 8 9 5 5 4 3 0 9 8 1 1 2 2 3 9 9 1 2 1 2 0 11 11 6 6 7 7 10 11 10 6 7 6 7 1...
result:
wrong answer Integer parameter [name=num] equals to 10, violates the range [0, 9] (test case 6)