답안 #702433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702433 2023-02-24T05:09:07 Z PixelCat Naan (JOI19_naan) C++14
29 / 100
107 ms 262144 KB
#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using LL = long long;
using pii = pair<int, int>;

struct Frac {
    __int128_t x, y;
    Frac(__int128_t _x = 0, __int128_t _y = 1) {
        x = _x; y = _y;
        simp();
    }
    void simp() {
        __int128_t g = __gcd(x, y);
        x /= g; y /= g;
    }
};
Frac operator-(const Frac &a) {
    return Frac(-a.x, a.y);
}
Frac operator+(const Frac &a, const Frac &b) {
    return Frac(a.x * b.y + a.y * b.x, a.y * b.y);
}
Frac operator-(const Frac &a, const Frac &b) {
    return a + (-b);
}
Frac operator*(const Frac &a, const Frac &b) {
    return Frac(a.x * b.x, a.y * b.y);
}
Frac operator/(const Frac &a, const Frac &b) {
    return Frac(a.x * b.y, a.y * b.x);
}
bool operator==(const Frac &a, const Frac &b) {
    return a.x * b.y == a.y * b.x;
}
bool operator<(const Frac &a, const Frac &b) {
    return a.x * b.y < a.y * b.x;
}
bool operator>(const Frac &a, const Frac &b) {
    return b < a;
}
bool operator<=(const Frac &a, const Frac &b) {
    return a < b || a == b;
}
bool operator>=(const Frac &a, const Frac &b) {
    return a > b || a == b;
}
ostream& operator<<(ostream& os, const Frac &a) {
    os << (LL)a.x << "/" << (LL)a.y;
    return os;
}

const int MAXN = 2010;

struct Meow {
    int v[MAXN];
    Frac tar;
    Frac inq[MAXN];
    Frac rem[MAXN];
    int pos_r, pos_l;
    Frac now;
    bool used;
    void init(int n, int l) {
        used = false;
        tar = Frac();
        For(i, 1, l) {
            cin >> v[i];
            tar.x += v[i];
            rem[i] = Frac(1);
            v[i] = v[i] * n;
        }
        tar = tar;
        pos_r = 1; pos_l = 1;
        now = Frac(0);
        push(1, Frac(0));
    }
    void push(int p0, Frac par) {
        while(pos_l < p0) {
            now = now - inq[pos_l] * v[pos_l];
            pos_l++;
        }
        // cout << rem[pos_r] << " " << tar << " " << now << "\n" << flush;
        Frac t = inq[pos_l] + rem[pos_r] + par - 1;
        inq[pos_l] = inq[pos_l] - t;
        now = now - t * v[pos_l];

        while(now + rem[pos_r] * v[pos_r] < tar) {
            now = now + rem[pos_r] * v[pos_r];
            inq[pos_r] = inq[pos_r] + rem[pos_r];
            rem[pos_r] = 0;
            pos_r++;
        }
        t = (tar - now) / v[pos_r];
        // assert(t <= rem[pos_r]);
        rem[pos_r] = rem[pos_r] - t;
        inq[pos_r] = inq[pos_r] + t;
        now = tar;
    }
    pair<int, Frac> get_front() {
        return make_pair(pos_r, 1 - rem[pos_r]);
    }
} meow[MAXN];

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // nyanyanyanyanya
    int n, l; cin >> n >> l;
    // assert(n <= 6);
    For(i, 1, n) meow[i].init(n, l);
    vector<int> ans;
    For(i, 1, n - 1) {
        pair<int, Frac> front(l + 1, 0);
        int min_id = -1;
        For(j, 1, n) if(!meow[j].used) {
            if(meow[j].get_front() < front) {
                front = meow[j].get_front();
                min_id = j;
            }
            // auto p = meow[j].get_front();
            // cout << j << " : " << p.F << " - " << p.S << "\n" << flush;
        }
        ans.eb(min_id);
        meow[min_id].used = true;
        For(j, 1, n) if(!meow[j].used) {
            meow[j].push(front.F, front.S);
        }
        front.S = front.F - 1 + front.S;
        cout << (LL)front.S.x << " " << (LL)front.S.y << "\n";
    }
    for(auto &i:ans) cout << i << " ";
    For(i, 1, n) if(!meow[i].used) cout << i << "\n";
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 261420 KB Output is correct
2 Correct 97 ms 261524 KB Output is correct
3 Correct 107 ms 261576 KB Output is correct
4 Correct 95 ms 261552 KB Output is correct
5 Correct 98 ms 261536 KB Output is correct
6 Correct 95 ms 261456 KB Output is correct
7 Correct 103 ms 261516 KB Output is correct
8 Correct 96 ms 261460 KB Output is correct
9 Correct 96 ms 261452 KB Output is correct
10 Correct 104 ms 261480 KB Output is correct
11 Correct 96 ms 261496 KB Output is correct
12 Correct 96 ms 261476 KB Output is correct
13 Correct 97 ms 261532 KB Output is correct
14 Correct 98 ms 261504 KB Output is correct
15 Correct 97 ms 261520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 261468 KB Output is correct
2 Correct 98 ms 261496 KB Output is correct
3 Correct 99 ms 261624 KB Output is correct
4 Correct 98 ms 261560 KB Output is correct
5 Correct 97 ms 261580 KB Output is correct
6 Correct 97 ms 261536 KB Output is correct
7 Correct 97 ms 261452 KB Output is correct
8 Correct 101 ms 261432 KB Output is correct
9 Correct 97 ms 261508 KB Output is correct
10 Correct 96 ms 261600 KB Output is correct
11 Correct 99 ms 261580 KB Output is correct
12 Correct 99 ms 261436 KB Output is correct
13 Correct 100 ms 261564 KB Output is correct
14 Correct 101 ms 261524 KB Output is correct
15 Correct 97 ms 261500 KB Output is correct
16 Correct 97 ms 261548 KB Output is correct
17 Correct 98 ms 261520 KB Output is correct
18 Correct 97 ms 261484 KB Output is correct
19 Correct 98 ms 261580 KB Output is correct
20 Correct 97 ms 261468 KB Output is correct
21 Correct 97 ms 261588 KB Output is correct
22 Correct 103 ms 261580 KB Output is correct
23 Correct 104 ms 261408 KB Output is correct
24 Correct 97 ms 261588 KB Output is correct
25 Correct 97 ms 261540 KB Output is correct
26 Correct 97 ms 261456 KB Output is correct
27 Correct 103 ms 261612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 261420 KB Output is correct
2 Correct 97 ms 261524 KB Output is correct
3 Correct 107 ms 261576 KB Output is correct
4 Correct 95 ms 261552 KB Output is correct
5 Correct 98 ms 261536 KB Output is correct
6 Correct 95 ms 261456 KB Output is correct
7 Correct 103 ms 261516 KB Output is correct
8 Correct 96 ms 261460 KB Output is correct
9 Correct 96 ms 261452 KB Output is correct
10 Correct 104 ms 261480 KB Output is correct
11 Correct 96 ms 261496 KB Output is correct
12 Correct 96 ms 261476 KB Output is correct
13 Correct 97 ms 261532 KB Output is correct
14 Correct 98 ms 261504 KB Output is correct
15 Correct 97 ms 261520 KB Output is correct
16 Correct 100 ms 261468 KB Output is correct
17 Correct 98 ms 261496 KB Output is correct
18 Correct 99 ms 261624 KB Output is correct
19 Correct 98 ms 261560 KB Output is correct
20 Correct 97 ms 261580 KB Output is correct
21 Correct 97 ms 261536 KB Output is correct
22 Correct 97 ms 261452 KB Output is correct
23 Correct 101 ms 261432 KB Output is correct
24 Correct 97 ms 261508 KB Output is correct
25 Correct 96 ms 261600 KB Output is correct
26 Correct 99 ms 261580 KB Output is correct
27 Correct 99 ms 261436 KB Output is correct
28 Correct 100 ms 261564 KB Output is correct
29 Correct 101 ms 261524 KB Output is correct
30 Correct 97 ms 261500 KB Output is correct
31 Correct 97 ms 261548 KB Output is correct
32 Correct 98 ms 261520 KB Output is correct
33 Correct 97 ms 261484 KB Output is correct
34 Correct 98 ms 261580 KB Output is correct
35 Correct 97 ms 261468 KB Output is correct
36 Correct 97 ms 261588 KB Output is correct
37 Correct 103 ms 261580 KB Output is correct
38 Correct 104 ms 261408 KB Output is correct
39 Correct 97 ms 261588 KB Output is correct
40 Correct 97 ms 261540 KB Output is correct
41 Correct 97 ms 261456 KB Output is correct
42 Correct 103 ms 261612 KB Output is correct
43 Runtime error 105 ms 262144 KB Execution killed with signal 9
44 Halted 0 ms 0 KB -