QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694456#6131. Tournamentucup-team3294#WA 1ms3660kbC++232.0kb2024-10-31 17:59:332024-10-31 17:59:35

Judging History

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

  • [2024-10-31 17:59:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3660kb
  • [2024-10-31 17:59:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define PII pair<int,int>
#define x first
#define y second
void solve() {
	int n,k;
	cin>>n>>k;
	vector<vector<int>> a(n+1,vector<int>(n+1));
	vector<vector<int>> v(n+1,vector<int>(n+1));
	if((n%2==0)&&((n/2)%2==0)&&(k==n-1)){
		vector<int> b(n+1);
		for(int i=1;i<=n;i+=2){
			for(int j=1;j<=n;j++){
				b[j]=0;
			}
			for(int j=1;j<=n;j+=2){
				for(int k=j;k<=n;k++){
					if(a[i][j]==0&&v[j][k]==0&&b[k]==0){
						a[i][j]=k;v[j][k]=1;b[j]=1;
						a[i][k]=j,v[k][j]=1;b[k]=1;
						if(k&1){
							a[i][j+1]=k+1,v[j+1][k+1]=1;v[k+1][j]=1;b[k+1]=1;
							a[i+1][j]=k+1;v[j][k+1]=1;v[k+1][j]=1;
							a[i+1][j+1]=k;v[j+1][k]=1;v[k][j+1]=1;
							a[i][k+1]=j+1;b[j+1]=1;
							a[i+1][k]=j+1;v[k][j+1]=1;v[j+1][k]=1;
							a[i+1][k+1]=j;v[k+1][j]=1;v[j][k+1]=1;
						}else{
							a[i][j+1]=k-1,v[j+1][k-1]=1;v[k-1][j]=1;b[k-1]=1;
							a[i+1][j]=k-1;v[j][k-1]=1;v[k-1][j]=1;
							a[i+1][j+1]=k;v[j+1][k]=1;v[k][j+1]=1;
							a[i][k-1]=j+1;b[j+1]=1;
							a[i+1][k]=j+1;v[k][j+1]=1;v[j+1][k]=1;
							a[i+1][k-1]=j;v[k-1][j]=1;v[j][k-1]=1;
						}
						break;
					}
				}
//				for(int i=1;i<=n;i++){
//			         for(int j=1;j<=n;j++){
////			           	st[j].insert(a[i][j]);
//			         	if(j!=1) cout<<" "<<a[i][j];
//			        	else cout<<a[i][j];
//		            	}cout<<"\n";
//	               	}
//	               	cout<<endl;
			}
		}
		set<int> st[n+1];
		for(int i=2;i<=n;i++){
			for(int j=1;j<=n;j++){
				st[j].insert(a[i][j]);
			}
		}
		for(int i=1;i<=n;i++){
			if(st[i].size()!=n-1){
				cout<<"Impossible\n";
				return;
			}
		}
		for(int i=2;i<=n;i++){
			for(int j=1;j<=n;j++){
				st[j].insert(a[i][j]);
				if(j!=1) cout<<" "<<a[i][j];
				else cout<<a[i][j];
			}cout<<"\n";
		}
	}else{
		cout<<"Impossible\n";
	}
}
signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int T=1;
	cin>>T;
	while(T--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

2
3 1
4 3

output:

Impossible
2 1 4 3
3 4 1 2
4 3 2 1

result:

ok 4 lines

Test #2:

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

input:

100
1 4
2 1
2 2
2 3
3 6
4 2
4 3
4 4
4 5
5 4
6 1
6 2
6 4
7 1
8 3
8 7
8 8
8 14
9 4
10 1
10 2
10 3
12 2
12 3
12 4
12 8
13 2
14 1
14 2
14 4
15 4
16 9
16 15
16 16
16 28
17 6
18 1
18 2
18 4
19 5
20 1
20 3
20 4
20 6
21 1
22 1
22 2
22 3
23 4
24 5
24 7
24 8
24 15
25 3
26 1
26 2
26 3
27 5
28 1
28 3
28 4
28 6
...

output:

Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
2 1 4 3
3 4 1 2
4 3 2 1
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
Impossible
2 1 4 3 6 5 8 7
3 4 1 2 7 8 5 6
4 3 2 1 8 7 6 5
5 6 7 8 1 2 3 4
6 5 8 7 2 1 4 3
7 8 5 6 3 4 1 2
8 7 6 5 4 3 2 1
Impossible...

result:

wrong answer 2nd lines differ - expected: '2 1', found: 'Impossible'