QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#850274#8940. Piggy Sortucup-team2796RE 1ms3996kbC++2313.9kb2025-01-09 23:10:482025-01-09 23:10:50

Judging History

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

  • [2025-01-09 23:10:50]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3996kb
  • [2025-01-09 23:10:48]
  • 提交

answer

#line 1 "library/Template/template.hpp"
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}
#line 2 "library/Utility/fastio.hpp"
#include <unistd.h>
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf

uint32_t pil = 0, pir = 0, por = 0;

struct Pre {
    char num[10000][4];
    constexpr Pre() : num() {
        for (int i = 0; i < 10000; i++) {
            int n = i;
            for (int j = 3; j >= 0; j--) {
                num[i][j] = n % 10 | '0';
                n /= 10;
            }
        }
    }
} constexpr pre;

inline void load() {
    memmove(ibuf, ibuf + pil, pir - pil);
    pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
    pil = 0;
    if (pir < SZ)
        ibuf[pir++] = '\n';
}

inline void flush() {
    fwrite(obuf, 1, por, stdout);
    por = 0;
}

void rd(char &c) {
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
}

void rd(string &x) {
    x.clear();
    char c;
    do {
        if (pil + 1 > pir)
            load();
        c = ibuf[pil++];
    } while (isspace(c));
    do {
        x += c;
        if (pil == pir)
            load();
        c = ibuf[pil++];
    } while (!isspace(c));
}

template <typename T> void rd_real(T &x) {
    string s;
    rd(s);
    x = stod(s);
}

template <typename T> void rd_integer(T &x) {
    if (pil + 100 > pir)
        load();
    char c;
    do
        c = ibuf[pil++];
    while (c < '-');
    bool minus = 0;
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (c == '-') {
            minus = 1, c = ibuf[pil++];
        }
    }
    x = 0;
    while ('0' <= c) {
        x = x * 10 + (c & 15), c = ibuf[pil++];
    }
    if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
        if (minus)
            x = -x;
    }
}

void rd(int &x) {
    rd_integer(x);
}
void rd(ll &x) {
    rd_integer(x);
}
void rd(i128 &x) {
    rd_integer(x);
}
void rd(uint &x) {
    rd_integer(x);
}
void rd(ull &x) {
    rd_integer(x);
}
void rd(u128 &x) {
    rd_integer(x);
}
void rd(double &x) {
    rd_real(x);
}
void rd(long double &x) {
    rd_real(x);
}

template <class T, class U> void rd(pair<T, U> &p) {
    return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
    if constexpr (N < std::tuple_size<T>::value) {
        auto &x = std::get<N>(t);
        rd(x);
        rd_tuple<N + 1>(t);
    }
}
template <class... T> void rd(tuple<T...> &tpl) {
    rd_tuple(tpl);
}

template <size_t N = 0, typename T> void rd(array<T, N> &x) {
    for (auto &d : x)
        rd(d);
}
template <class T> void rd(vector<T> &x) {
    for (auto &d : x)
        rd(d);
}

void read() {}
template <class H, class... T> void read(H &h, T &...t) {
    rd(h), read(t...);
}

void wt(const char c) {
    if (por == SZ)
        flush();
    obuf[por++] = c;
}
void wt(const string s) {
    for (char c : s)
        wt(c);
}
void wt(const char *s) {
    size_t len = strlen(s);
    for (size_t i = 0; i < len; i++)
        wt(s[i]);
}

template <typename T> void wt_integer(T x) {
    if (por > SZ - 100)
        flush();
    if (x < 0) {
        obuf[por++] = '-', x = -x;
    }
    int outi;
    for (outi = 96; x >= 10000; outi -= 4) {
        memcpy(out + outi, pre.num[x % 10000], 4);
        x /= 10000;
    }
    if (x >= 1000) {
        memcpy(obuf + por, pre.num[x], 4);
        por += 4;
    } else if (x >= 100) {
        memcpy(obuf + por, pre.num[x] + 1, 3);
        por += 3;
    } else if (x >= 10) {
        int q = (x * 103) >> 10;
        obuf[por] = q | '0';
        obuf[por + 1] = (x - q * 10) | '0';
        por += 2;
    } else
        obuf[por++] = x | '0';
    memcpy(obuf + por, out + outi + 4, 96 - outi);
    por += 96 - outi;
}

template <typename T> void wt_real(T x) {
    ostringstream oss;
    oss << fixed << setprecision(15) << double(x);
    string s = oss.str();
    wt(s);
}

void wt(int x) {
    wt_integer(x);
}
void wt(ll x) {
    wt_integer(x);
}
void wt(i128 x) {
    wt_integer(x);
}
void wt(uint x) {
    wt_integer(x);
}
void wt(ull x) {
    wt_integer(x);
}
void wt(u128 x) {
    wt_integer(x);
}
void wt(double x) {
    wt_real(x);
}
void wt(long double x) {
    wt_real(x);
}

template <class T, class U> void wt(const pair<T, U> val) {
    wt(val.first);
    wt(' ');
    wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
    if constexpr (N < std::tuple_size<T>::value) {
        if constexpr (N > 0) {
            wt(' ');
        }
        const auto x = std::get<N>(t);
        wt(x);
        wt_tuple<N + 1>(t);
    }
}
template <class... T> void wt(tuple<T...> tpl) {
    wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}
template <class T> void wt(const vector<T> val) {
    auto n = val.size();
    for (size_t i = 0; i < n; i++) {
        if (i)
            wt(' ');
        wt(val[i]);
    }
}

void print() {
    wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
    wt(head);
    if (sizeof...(Tail))
        wt(' ');
    print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
    flush();
}
} // namespace fastio

using fastio::flush;
using fastio::print;
using fastio::read;

inline void first(bool i = true) {
    print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
    print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
    print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
    print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
    print(i ? "Yes" : "No");
}
inline void No() {
    print("No");
}
inline void YES(bool i = true) {
    print(i ? "YES" : "NO");
}
inline void NO() {
    print("NO");
}
inline void Yay(bool i = true) {
    print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
    print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
    print(i ? "POSSIBLE" : "IMPOSSIBLE");
}

/**
 * @brief Fast IO
 */
#line 3 "sol.cpp"

#line 2 "library/Math/fraction.hpp"

template <typename T> struct Frac {
    T a, b;
    Frac(T _a = 0) {
        init(_a, 1);
    }
    Frac(T _a, T _b) {
        init(_a, _b);
    }
    Frac &init(T _a, T _b) {
        T g = GCD(_a, _b);
        a = _a / g, b = _b / g;
        if (b < 0)
            a = -a, b = -b;
        return *this;
    }
    Frac inv() const {
        return Frac(b, a);
    }
    Frac operator-() const {
        return Frac(-a, b);
    }
    Frac &operator+=(const Frac &x) {
        return init(a * x.b + x.a * b, b * x.b);
    }
    Frac &operator-=(const Frac &x) {
        return init(a * x.b - x.a * b, b * x.b);
    }
    Frac &operator*=(const Frac &x) {
        return init(a * x.a, b * x.b);
    }
    Frac &operator/=(const Frac &x) {
        return init(a * x.b, b * x.a);
    }
    Frac operator+(const Frac &x) const {
        return Frac(*this) += x;
    }
    Frac operator-(const Frac &x) const {
        return Frac(*this) -= x;
    }
    Frac operator*(const Frac &x) const {
        return Frac(*this) *= x;
    }
    Frac operator/(const Frac &x) const {
        return Frac(*this) /= x;
    }
    bool operator<(const Frac &x) const {
        return a * x.b < b * x.a;
    }
    bool operator>(const Frac &x) const {
        return x < *this;
    }
    bool operator<=(const Frac &x) const {
        return !(x < *this);
    }
    bool operator>=(const Frac &x) const {
        return !(*this < x);
    }
    bool operator==(const Frac &x) const {
        return (*this <= x and x <= *this);
    }
    bool operator!=(const Frac &x) const {
        return !(*this == x);
    }
    T GCD(T a, T b) {
        if (b == 0)
            return a;
        else
            return GCD(b, a % b);
    }

    friend istream &operator>>(istream &is, Frac &x) {
        return is >> x.a >> x.b;
    }
    friend ostream &operator<<(ostream &os, const Frac &x) {
        return os << x.a << '/' << x.b;
    }
};
template <typename T> Frac<T> between(const Frac<T> &x, const Frac<T> &y) {
    if (x.a < x.b and y.b < y.a)
        return Frac(1);
    else if (x.b <= x.a) {
        T add = floor(x.a / x.b);
        return between(x - add, y - add) + add;
    } else
        return between(y.inv(), x.inv()).inv();
}

/**
 * @brief Fraction
 * @docs docs/fraction.md
 */
#line 5 "sol.cpp"

void solve(int _rot) {
    // print("Case #"+to_string(_rot)+":");
    int n, m;
    read(n, m);
    vector a(m, vector<int>(n));
    read(a);

    if (n == 1) {
        print(1);
        return;
    }

    vector<i128> time(m);
    rep(i, 0, m) {
        rep(j, 0, n) time[i] += a[i][j];
    }
    using P = pair<Frac<i128>, int>;
    vector<P> lines;
    auto rec = [&](auto &rec, int N, int M, vector<vector<int>> &info,
                   vector<int> &id) -> void {
        if (N == 1) {
            Frac<i128> speed(info[1][0] - info[0][0], time[1] - time[0]);
            lines.push_back({speed, id[0]});
            return;
        }
        rep(x, 0, N) {
            Frac<i128> speed(info[1][x] - info[0][0], time[1] - time[0]);
            bool ch = 1;
            vector<int> del(M);
            del[1] = x;
            rep(i, 2, M) {
                i128 diff = time[i] - time[0];
                if ((diff * speed.a) % speed.b != 0) {
                    ch = 0;
                    break;
                }
                i128 cur = (diff * speed.a) / speed.b + info[0][0];
                del[i] = LB(info[i], cur);
                if (info[i][del[i]] != cur) {
                    ch = 0;
                    break;
                }
            }
            if (ch) {
                lines.push_back({speed, id[0]});
                vector<vector<int>> ninfo(M);
                rep(i, 0, M) {
                    rep(j, 0, N) if (j != del[i]) {
                        ninfo[i].push_back(info[i][j]);
                    }
                }
                vector<int> nid = id;
                nid.erase(nid.begin());
                rec(rec, N - 1, M, ninfo, nid);
                return;
            }
        }
        show("OUT");
        exit(0);
    };
    vector<int> init(n);
    iota(ALL(init), 0);
    rec(rec, n, m, a, init);

    sort(ALL(lines));
    // show(lines);
    vector<int> ret(n);
    rep(i, 0, n) {
        ret[lines[i].second] = i + 1;
    }
    print(ret);
}

int main() {
    int t;
    read(t);
    rep(rot, 0, t) solve(rot + 1);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 4
1 2
3 4
5 6
7 8
1 2
1
1
3 4
1 2 3
6 9 9
10 15 17
12 18 21

output:

1 2
1
3 1 2

result:

ok 3 lines

Test #2:

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

input:

41
1 2
-19
9531
2 3
11 13
3175 4759
2211 3313
10 19
-54 -25 -19 -18 -1 3 61 63 85 88
-54 753 863 2397 3111 4649 4671 4756 5507 7762
-54 369 479 1245 1575 2345 2367 2452 2819 3922
-54 553 663 1797 2311 3449 3471 3556 4107 5762
-54 87 197 399 447 653 675 760 845 1102
-54 320 430 1098 1379 2051 2073 21...

output:

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

result:

ok 41 lines

Test #3:

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

input:

46
8 12
-50 -35 -20 -10 -9 4 13 91
-24 30 32 143 146 147 173 221
-44 -8 10 13 26 27 61 103
-46 -12 -3 8 14 15 45 99
-22 32 36 147 158 159 189 237
-47 -14 -11 7 8 9 37 97
-31 18 23 104 105 117 129 165
-45 -10 5 9 20 21 53 101
-36 8 18 74 75 77 119 125
-30 20 24 110 111 125 131 173
-48 -19 -16 2 3 6 2...

output:

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

result:

ok 46 lines

Test #4:

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

input:

48
3 4
-4952 -1539 836
-4294 5909 12778
-4811 57 3395
-4529 3249 8513
8 11
-9107 -1143 1324 3936 4088 4381 7658 9440
-2753 531 6032 14986 18097 18264 20240 22022
-5224 -120 5276 9673 12692 12763 15347 17129
-2047 717 6248 16504 19621 19856 21638 23420
-6283 -399 4952 7396 10304 10477 13250 15032
-48...

output:

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

result:

ok 48 lines

Test #5:

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

input:

40
10 20
-4289879 -3663596 -3442064 -3379220 -670906 -329052 1547135 1640345 2662172 3577480
-4280827 -3609576 -3374758 -3321039 -598417 -319197 1583489 1685532 2700424 3645662
-4276115 -3581456 -3339722 -3290753 -560683 -314067 1602413 1709054 2720336 3681154
-4271279 -3552596 -3303764 -3259670 -52...

output:

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

result:

ok 40 lines

Test #6:

score: -100
Runtime Error

input:

79
5 7
-5 -1 7 8 10
-1 1 10 19 20
-1 4 10 25 26
-1 5 10 27 28
-2 -1 10 13 14
-4 -1 9 10 10
-1 3 10 23 24
5 6
-7 -5 2 3 5
2 3 11 13 14
-5 -3 2 3 6
2 3 7 9 12
2 3 3 5 10
2 3 5 7 11
3 4
-10 -7 -5
-10 1 3
-10 -4 -2
-10 0 2
5 10
-10 -6 -1 6 7
-10 4 7 9 11
-10 7 8 13 13
-10 7 14 16 19
-10 7 12 15 17
-10 6...

output:


result: