QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#91167#6131. TournamentsychengAC ✓22ms6900kbC++202.1kb2023-03-27 15:52:062023-03-27 15:52:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-27 15:52:11]
  • 评测
  • 测评结果:AC
  • 用时:22ms
  • 内存:6900kb
  • [2023-03-27 15:52:06]
  • 提交

answer

#pragma comment(linker, "/STACK:16777216")
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <unordered_set>
#include <cstring>
#include <unordered_map>
#include "math.h"
#include <stdio.h>
#include <bitset>
#include <string>
#include <complex>
#include <iomanip>
#include <stack>
#include <deque>
#include <string>
#include<assert.h>
typedef long long ll;

using namespace std;
const ll MOD = 998244353;
const ll MAXN = 100005;
const double pi = acos(-1);

int a[2050][2050];

void rec(int sz) {
    if (sz == 0)
        return;
    rec(sz / 2);
    if (sz == 1) {
        a[0][0] = 1;
    }
    for (int i = sz / 2; i < sz; i++) {
        for (int j = sz / 2; j < sz; j++) {
            a[i][j] = a[i - sz / 2][j - sz / 2];
        }
    }
    for (int i = 0; i < sz / 2; i++) {
        for (int j = sz / 2; j < sz; j++) {
            a[i][j] = a[i][j - sz / 2] + sz / 2;
        }
    }
    for (int i = sz / 2; i < sz; i++) {
        for (int j = 0; j < sz / 2; j++) {
            a[i][j] = a[i - sz / 2][j] + sz / 2;
        }
    }
}


void solve() {
    int t;
    cin >> t;
    while(t--) {
        int n, k;
        cin >> n >> k;
        int maxi = 1;
        while (n % (maxi * 2) == 0) {
            maxi *= 2;
        }

        if (k > maxi - 1) {
            cout << "Impossible" << endl;
            continue;
        }

        rec(maxi);


        for (int i = 0; i < maxi; i++) {
            for (int j = maxi; j < n; j++) {
                a[i][j] = a[i][j - maxi] + maxi;
            }
        }

        for (int i = 1; i <= k; i++) {
            for (int j = 0; j < n; j++) {
                if (j != 0)
                    cout << " ";
                cout << a[i][j];
            }
            cout << endl;
        }
    }
}


int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.tie(0);
    cout.precision(20);
    //precalc();
    //freopen("../in.txt", "r", stdin);
    //freopen("../out.txt", "w", stdout);
    solve();
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3528kb

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

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 6 5
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:

ok 194 lines

Test #3:

score: 0
Accepted
time: 22ms
memory: 6900kb

input:

5
512 511
512 513
896 120
896 130
960 60

output:

2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102 101 ...

result:

ok 693 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 3352kb

input:

30
184 17
154 3
172 2
138 10
156 13
130 3
168 7
170 4
146 3
198 3
134 11
116 1
132 7
140 2
130 9
174 5
182 4
106 4
174 2
182 2
104 14
168 13
198 1
110 3
176 9
198 9
156 11
148 2
118 10
150 8

output:

Impossible
Impossible
2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95...

result:

ok 47 lines