QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#469303 | #7227. The Magic Square | inksamurai | WA | 0ms | 3724kb | C++23 | 1.6kb | 2024-07-09 17:17:57 | 2024-07-09 17:17:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rng(i,c,n) for(int i=c;i<n;i++)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int) a.size()
#define all(a) a.begin(),a.end()
#define vec(...) vector<__VA_ARGS__>
#define _3zlqvu8 ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
#define nare cout<<"Impossible\n"; return;
#define yare cout<<"Possible\n";
void slv(){
int n;
cin>>n;
if(n==2 or n==3 or n==5){
nare;
}
if(n==4){
yare;
cout<<"2\n";
cout<<"1 2\n3 4\n";
return;
}else if(n==7){
yare;
cout<<"4\n";
cout<<"1 1 2 2\n";
cout<<"1 1 2 2\n";
cout<<"3 3 4 5\n";
cout<<"3 3 6 7\n";
return;
}
if(n%2==0){
int k=(n-2)/2;
int c=2;
cout<<k<<"\n";
rep(i,k+1){
rep(j,k+1){
if(i==k or j==k) cout<<(c++)<<" ";
else cout<<"1 ";
}
cout<<"\n";
}
}else{
if((n-1)%4==0){
int k=n/4+1;
int c=2;
yare;
cout<<k<<"\n";
rep(i,k){
rep(j,k){
if(i<k-2 and j<k-2){
cout<<"1 ";
}else{
cout<<(c++)<<" ";
}
}
cout<<"\n";
}
}else{
nare;
// n-=3;
// int k=(n-2)/2;
// int c=5;
// rep(i,k+1){
// rep(j,k+1){
// if(i==k or j==k) cout<<(c++)<<" ";
// else cout<<"1 ";
// }
// cout<<"\n";
// }
}
}
}
signed main(){
_3zlqvu8;
slv();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
input:
2
output:
Impossible
result:
ok No solution for 2 squares
Test #2:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
4
output:
Possible 2 1 2 3 4
result:
ok answer 4 squares of 1 different sizes in total 2 * 2
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
input:
1
output:
Possible 1 2
result:
wrong answer Illegal construction