QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469305#7227. The Magic SquareinksamuraiWA 0ms3656kbC++231.6kb2024-07-09 17:18:132024-07-09 17:18:16

Judging History

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

  • [2024-07-09 17:18:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3656kb
  • [2024-07-09 17:18:13]
  • 提交

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: 3656kb

input:

2

output:

Impossible

result:

ok No solution for 2 squares

Test #2:

score: 0
Accepted
time: 0ms
memory: 3652kb

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: 3592kb

input:

1

output:

Possible
1
2 

result:

wrong answer Illegal construction