QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#594571#6131. TournamentPonyHexWA 1ms5764kbC++202.3kb2024-09-28 08:31:012024-09-28 08:31:02

Judging History

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

  • [2024-09-28 08:31:02]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5764kb
  • [2024-09-28 08:31:01]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define ll long long
//#define double long double
#define lc u<<1
#define rc u<<1|1
#define X first
#define Y second
#define endl "\n"
#define int long long
const int N = 1e5 + 50;
const int M = 5e5 + 5;
const ll maxm = 1e18 + 5;
const ll mod = 998244353;
int dx[] = { -1,0,1,0 };
int dy[] = { 0,1,0,-1 };
//random_shuffle(id + 1, id + n + 1);
ll ksm(ll a, ll b);
ll gcd(ll a, ll b);

template<class T>inline void read(T& x) {
	x = 0;
	char c = getchar();
	while (!isdigit(c))c = getchar();
	while (isdigit(c))x = x * 10 + (c & 15), c = getchar();
}

void write(ll x)
{
	if (x < 0)
		putchar('-'), x = -x;
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}

ll mp[1005][1005];
int n, k;
int lowbit(int n) {
	return n & -n;
}

void solve() {
	cin >> n >> k;
	if (k > lowbit(n) - 1) {
		cout << "Impossible" << endl;
		return;
	}
	for (int j = 1; j <= n - 1; j += 2) {//枚举列
		if ((j + 1)/2 % 2 == 1) {
			ll st = j;
			for (int i = 0; i < n; i++) {
				mp[st][j] = i + 1;
				st++;
				if (st == n + 1)st = 1;
			}
		}
		else {
			ll st = j+1;
			j++;
			for (int i = 0; i < n; i++) {
				mp[st][j] = i + 1;
				st--;
				if (st == 0)st = n;
			}
			j--;
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n - 1; j += 2) {
			if ((j + 1) / 2 % 2 == 1) {
				ll st = j;
				if (mp[i][j] % 2 == 1)mp[i][j + 1] = mp[i][j] + 1;
				else mp[i][j + 1] = mp[i][j] - 1;
			}
			else {
				ll st = j;
				j++;
				if (mp[i][j] % 2 == 1)mp[i][j-1] = mp[i][j] + 1;
				else mp[i][j-1] = mp[i][j] - 1;
				j--;
			}
		}
	}
	for (int i = 2; i <= k + 1; i++) {
		cout << mp[i][1];
		for (int j = 2; j <= n; j++) {
			cout << " " << mp[i][j];
		}
		cout << endl;
	}

}


signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int T = 1;
	cin >> T;
	//read(T);
	while (T--)
		solve();
	return 0;
}

/*PonyHex*/


ll ksm(ll a, ll b) {
	ll base = a;
	ll ans = 1;
	while (b) {
		if (b & 1)ans *= base % mod;
		ans %= mod;
		base *= base; base %= mod;
		b >>= 1;
	}
	return ans % mod;
}
ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
2 1
Impossible
Impossible
Impossible
2 1 4 3
3 4 1 2
2 1 4 3
3 4 1 2
4 3 2 1
Impossible
Impossible
Impossible
2 1 4 3 4 3
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
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 ...

result:

wrong answer 14th lines differ - expected: '2 1 4 3 6 5', found: '2 1 4 3 4 3'