답안 #337403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337403 2020-12-20T14:37:24 Z ryangohca Naan (JOI19_naan) C++17
100 / 100
3672 ms 179280 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
struct fraction {
    __int128_t n, d;
    fraction(__int128_t _n, __int128_t _d) {
        n = _n, d = _d;
        __int128_t g = std::__gcd(n, d); n /= g, d /= g;
        if (d < 0) n *= -1, d *= -1;
    }
    fraction(__int128_t _n) : fraction(_n, 1) {}
    fraction() : fraction(0) {}
    friend bool operator < (const fraction& l, const fraction& r) { return l.n * r.d < r.n * l.d; }
    friend bool operator <= (const fraction& l, const fraction& r) { return l.n * r.d <= r.n * l.d; }
    friend bool operator > (const fraction& l, const fraction& r) { return l.n * r.d > r.n * l.d; }
    friend bool operator >= (const fraction& l, const fraction& r) { return l.n * r.d >= r.n * l.d; }
    friend bool operator == (const fraction& l, const fraction& r) { return l.n == r.n && l.d == r.d; }
    friend bool operator != (const fraction& l, const fraction& r) { return !(l == r); }
    fraction operator - () const { return fraction(-n, d); }
    friend fraction operator + (const fraction& l, const fraction& r) { return fraction(l.n * r.d + r.n * l.d, l.d * r.d); }
    friend fraction operator - (const fraction& l, const fraction& r) { return fraction(l.n * r.d - r.n * l.d, l.d * r.d); }
    friend fraction operator * (const fraction& l, const fraction& r) { return fraction(l.n * r.n, l.d * r.d); }
    friend fraction operator * (const fraction& l, int r) { return l * fraction(r, 1); }
    friend fraction operator * (int r, const fraction& l) { return l * r; }
    friend fraction operator / (const fraction& l, const fraction& r) { return l * fraction(r.d, r.n); }
    friend fraction operator / (const fraction& l, const int& r) { return l / fraction(r, 1); }
    friend fraction operator / (const int& l, const fraction& r) { return fraction(l, 1) / r; }
    friend fraction& operator += (fraction& l, const fraction& r) { return l = l + r; }
    friend fraction& operator -= (fraction& l, const fraction& r) { return l = l - r; }
    template <class T> friend fraction& operator *= (fraction& l, const T& r) { return l = l * r; }
    template <class T> friend fraction& operator /= (fraction& l, const T& r) { return l = l / r; }
};
 
int nums[2000][2000];
fraction cuts[2000][2000];
vector<fraction> confirmed;
vector<int> order;
bool ordered[2000];
inline int read() {
    int x = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') ch = getchar_unlocked();
    while (ch >= '0' && ch <= '9') {
		x = (x << 3) + (x << 1) + (ch & 15);
		ch = getchar_unlocked();
	}
	return x;
}
main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n = read(), l = read();
    fraction zero = fraction(0, 1), one = fraction(1, 1);
    for (int i = 0; i < n; i++){
        fraction need;
        for (int j = 0; j < l; j++) {
            nums[i][j] = read();
            need += fraction(nums[i][j], 1);
        }
        need /= fraction(n, 1);
        fraction curr, prevleft;
        int idx = 0;
        for (int j = 1; j < n; j++){
            while (need > curr){
                fraction willtake = (one - prevleft) * fraction(nums[i][idx], 1);
                if (curr + willtake <= need){
                    curr += willtake;
                    idx++;
                    prevleft = zero;
                } else {
                    prevleft += (need - curr) / fraction(nums[i][idx], 1);
                    curr = need;
                    break;
                }
            }
            cuts[i][j] = fraction(idx, 1) + prevleft;
            curr = fraction(0, 1);
        }
    }
    for (int i = 1; i < n; i++){ // cut i
        pair<fraction, int> giveCut = {fraction(1e9, 1), -1};
        for (int j = 0; j < n; j++){ // person j
            if (!ordered[j]) {
                pair<fraction, int> other = {cuts[j][i], j};
                giveCut = min(giveCut, other);
            }
        }
        ordered[giveCut.second] = true;
        confirmed.push_back(giveCut.first);
        order.push_back(giveCut.second);
    }
    for (int i = 0; i < n; i++){
        if (!ordered[i]) order.push_back(i);
    }
    for (fraction i : confirmed){
        cout << (int)i.n << ' ' << (int)i.d << '\n';
    }
    for (auto i : order) cout << i + 1 << ' ';
    cout << '\n';
}

Compilation message

naan.cpp:50:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main(){
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 125552 KB Output is correct
2 Correct 66 ms 125552 KB Output is correct
3 Correct 69 ms 125636 KB Output is correct
4 Correct 68 ms 125676 KB Output is correct
5 Correct 66 ms 125548 KB Output is correct
6 Correct 68 ms 125548 KB Output is correct
7 Correct 68 ms 125604 KB Output is correct
8 Correct 68 ms 125676 KB Output is correct
9 Correct 66 ms 125548 KB Output is correct
10 Correct 68 ms 125676 KB Output is correct
11 Correct 70 ms 125660 KB Output is correct
12 Correct 69 ms 125676 KB Output is correct
13 Correct 67 ms 125592 KB Output is correct
14 Correct 70 ms 125676 KB Output is correct
15 Correct 72 ms 125676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 125604 KB Output is correct
2 Correct 65 ms 125676 KB Output is correct
3 Correct 65 ms 125696 KB Output is correct
4 Correct 65 ms 125676 KB Output is correct
5 Correct 64 ms 125676 KB Output is correct
6 Correct 65 ms 125676 KB Output is correct
7 Correct 66 ms 125676 KB Output is correct
8 Correct 67 ms 125676 KB Output is correct
9 Correct 68 ms 125660 KB Output is correct
10 Correct 68 ms 125676 KB Output is correct
11 Correct 68 ms 125676 KB Output is correct
12 Correct 66 ms 125548 KB Output is correct
13 Correct 67 ms 125676 KB Output is correct
14 Correct 68 ms 125676 KB Output is correct
15 Correct 69 ms 125676 KB Output is correct
16 Correct 68 ms 125748 KB Output is correct
17 Correct 73 ms 125676 KB Output is correct
18 Correct 72 ms 125676 KB Output is correct
19 Correct 68 ms 125676 KB Output is correct
20 Correct 70 ms 125676 KB Output is correct
21 Correct 70 ms 125748 KB Output is correct
22 Correct 71 ms 125680 KB Output is correct
23 Correct 71 ms 125636 KB Output is correct
24 Correct 71 ms 125676 KB Output is correct
25 Correct 73 ms 125676 KB Output is correct
26 Correct 73 ms 125620 KB Output is correct
27 Correct 76 ms 125676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 125552 KB Output is correct
2 Correct 66 ms 125552 KB Output is correct
3 Correct 69 ms 125636 KB Output is correct
4 Correct 68 ms 125676 KB Output is correct
5 Correct 66 ms 125548 KB Output is correct
6 Correct 68 ms 125548 KB Output is correct
7 Correct 68 ms 125604 KB Output is correct
8 Correct 68 ms 125676 KB Output is correct
9 Correct 66 ms 125548 KB Output is correct
10 Correct 68 ms 125676 KB Output is correct
11 Correct 70 ms 125660 KB Output is correct
12 Correct 69 ms 125676 KB Output is correct
13 Correct 67 ms 125592 KB Output is correct
14 Correct 70 ms 125676 KB Output is correct
15 Correct 72 ms 125676 KB Output is correct
16 Correct 67 ms 125604 KB Output is correct
17 Correct 65 ms 125676 KB Output is correct
18 Correct 65 ms 125696 KB Output is correct
19 Correct 65 ms 125676 KB Output is correct
20 Correct 64 ms 125676 KB Output is correct
21 Correct 65 ms 125676 KB Output is correct
22 Correct 66 ms 125676 KB Output is correct
23 Correct 67 ms 125676 KB Output is correct
24 Correct 68 ms 125660 KB Output is correct
25 Correct 68 ms 125676 KB Output is correct
26 Correct 68 ms 125676 KB Output is correct
27 Correct 66 ms 125548 KB Output is correct
28 Correct 67 ms 125676 KB Output is correct
29 Correct 68 ms 125676 KB Output is correct
30 Correct 69 ms 125676 KB Output is correct
31 Correct 68 ms 125748 KB Output is correct
32 Correct 73 ms 125676 KB Output is correct
33 Correct 72 ms 125676 KB Output is correct
34 Correct 68 ms 125676 KB Output is correct
35 Correct 70 ms 125676 KB Output is correct
36 Correct 70 ms 125748 KB Output is correct
37 Correct 71 ms 125680 KB Output is correct
38 Correct 71 ms 125636 KB Output is correct
39 Correct 71 ms 125676 KB Output is correct
40 Correct 73 ms 125676 KB Output is correct
41 Correct 73 ms 125620 KB Output is correct
42 Correct 76 ms 125676 KB Output is correct
43 Correct 356 ms 131292 KB Output is correct
44 Correct 1827 ms 154424 KB Output is correct
45 Correct 619 ms 143852 KB Output is correct
46 Correct 106 ms 128620 KB Output is correct
47 Correct 1091 ms 148844 KB Output is correct
48 Correct 2754 ms 141852 KB Output is correct
49 Correct 658 ms 134252 KB Output is correct
50 Correct 3286 ms 159244 KB Output is correct
51 Correct 1143 ms 145804 KB Output is correct
52 Correct 2692 ms 159904 KB Output is correct
53 Correct 2521 ms 155168 KB Output is correct
54 Correct 69 ms 125676 KB Output is correct
55 Correct 1345 ms 132756 KB Output is correct
56 Correct 1553 ms 150576 KB Output is correct
57 Correct 1261 ms 147188 KB Output is correct
58 Correct 2276 ms 151868 KB Output is correct
59 Correct 1289 ms 147496 KB Output is correct
60 Correct 2944 ms 179072 KB Output is correct
61 Correct 3087 ms 179052 KB Output is correct
62 Correct 3640 ms 179052 KB Output is correct
63 Correct 3471 ms 179256 KB Output is correct
64 Correct 3039 ms 179280 KB Output is correct
65 Correct 3672 ms 165700 KB Output is correct
66 Correct 3565 ms 165780 KB Output is correct
67 Correct 3075 ms 165816 KB Output is correct
68 Correct 1511 ms 150100 KB Output is correct
69 Correct 1338 ms 152812 KB Output is correct
70 Correct 1871 ms 152492 KB Output is correct
71 Correct 2145 ms 161888 KB Output is correct