QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#469309#7227. The Magic SquareinksamuraiWA 1ms3616kbC++231.7kb2024-07-09 17:19:572024-07-09 17:19:59

Judging History

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

  • [2024-07-09 17:19:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-07-09 17:19:57]
  • 提交

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==1){
		yare;
		cout<<"1\n1\n";
		return;
	}else 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;
		yare;
		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: 3556kb

input:

2

output:

Impossible

result:

ok No solution for 2 squares

Test #2:

score: 0
Accepted
time: 1ms
memory: 3592kb

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: 0
Accepted
time: 0ms
memory: 3612kb

input:

1

output:

Possible
1
1

result:

ok answer 1 squares of 1 different sizes in total 1 * 1

Test #4:

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

input:

3

output:

Impossible

result:

ok No solution for 3 squares

Test #5:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

5

output:

Impossible

result:

ok No solution for 5 squares

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3584kb

input:

6

output:

Possible
2
1 1 2 
1 1 3 
4 5 6 

result:

wrong answer Illegal construction