QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784470#3569. Foul PlaySGColin#100 ✓41ms4844kbC++201.6kb2024-11-26 15:06:072024-11-26 15:06:28

Judging History

This is the latest submission verdict.

  • [2024-11-26 15:06:28]
  • Judged
  • Verdict: 100
  • Time: 41ms
  • Memory: 4844kb
  • [2024-11-26 15:06:07]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define pb push_back
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)

constexpr int N = 1025;

bool beat[N][N];

int n, order[N];

inline void work() {
    vector<int> s[N], busy, free;
    rep(i, 1, n) rep(j, 1, n) {
        char c = getchar();
        while (!isdigit(c)) c = getchar();
        beat[i][j] = (c == '1');
    }
    rep(i, 1, n) {
        if (!beat[1][i]) {
            rep(j, 1, n) {
                if (beat[j][i] && beat[1][j]) {s[j].eb(i); break;}
            }
        }
    }
    rep(i, 2, n) if (beat[1][i]) s[i].empty() ? free.eb(i) : busy.eb(i);
    sort(all(busy), [&](int x, int y){return s[x].size() > s[y].size();});
    int tot = 0;
    for (auto x : busy) {
        int k = 0;
        while ((1 << k) < s[x].size() + 1) ++k;
        k = (1 << k) - s[x].size() - 1;
        order[++tot] = x;
        for (auto y : s[x]) order[++tot] = y;
        while (k--) {order[++tot] = free.back(); free.pop_back();}
    }
    for (auto x : free) order[++tot] = x;
    order[++tot] = 1;
    for (int k = 0; (1 << k) < n; ++k)
        for (int i = 1; i <= n; i += (1 << (k + 1))) {
            int &x = order[i], &y = order[i + (1 << k)];
            printf("%d %d\n", x, y);
            if (beat[y][x]) swap(x, y);
        }
}

int main() {
    while (scanf("%d", &n) != EOF) work();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Pretests


Final Tests

Test #1:

score: 100
Accepted
time: 41ms
memory: 4844kb

input:

4
0110
0011
0000
1010
8
00111010
10101111
00010010
01000101
00110010
10101011
00010000
10101010
2
01
00
4
0101
0000
1100
0110
4
0011
1000
0100
0110
4
0111
0000
0100
0110
4
0101
0010
1000
0110
4
0011
1010
0000
0110
4
0111
0010
0000
0110
4
0110
0001
0100
1010
4
0101
0001
1100
0010
4
0011
1001
0100
001...

output:

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

result:

ok correct