답안 #201384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201384 2020-02-10T10:46:31 Z BThero Naan (JOI19_naan) C++17
100 / 100
693 ms 100216 KB
// Why am I so dumb? :c
// chrono::system_clock::now().time_since_epoch().count()
                                                  
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;   
typedef pair<int, int> pii;
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int MAXN = (int)2e3 + 5;

struct Ratio {
    ll a, b;

    Ratio() {
        a = 0;
        b = 1;
    }

    Ratio(ll a, ll b) : a(a), b(b) {}

    void simplify() {
        ll c = __gcd(a, b);
        a /= c;
        b /= c;
    }         
};         

bool operator < (Ratio f, Ratio s) {
    return (double)f.a / f.b < (double)s.a / s.b;
}

bool operator > (Ratio f, Ratio s) {
    return s < f;
}

bool operator == (Ratio f, Ratio s) {
    return !(f < s) && !(f > s);
}

bool operator <= (Ratio f, Ratio s) {
    return f < s || f == s;
}

bool operator >= (Ratio f, Ratio s) {
    return s <= f;
}

ll lcm(ll a, ll b) {
    return a / __gcd(a, b) * b;
}

Ratio operator + (Ratio f, Ratio s) {
    ll c = lcm(f.b, s.b);
    return Ratio(f.a * c / f.b + s.a * c / s.b, c);
}

void operator += (Ratio &f, Ratio s) {
    f = f + s;
}

vector<Ratio> V[MAXN];

ll arr[MAXN][MAXN];

bool used[MAXN];

int ptr[MAXN];

int n, m;

void solve() {
    scanf("%d %d", &n, &m);

    for (int i = 1; i <= n; ++i) {
        ll mean = 0, cur = 0;

        for (int j = 1; j <= m; ++j) {
            scanf("%lld", &arr[i][j]);
            mean += arr[i][j];
            arr[i][j] *= n;
        }

        ll pref = 0;

        for (int j = 1; j <= m; ++j) {
            ll Y = 0, X = arr[i][j];

            while (Y < X) {
                if (cur + (X - Y) > mean) {
                    Y += (mean - cur);
                    cur = mean;                                                                                                                                                                                           
                }
                else {
                    cur += (X - Y);
                    Y = X;        
                }

                if (cur == mean) {
                    V[i].pb(Ratio((j - 1) * X + Y, X));
                    cur = 0;
                }
            }

            pref += X;      
        }

        assert(V[i].size() == n);                        
    }

    vector<int> perm;
    
    for (int j = 0; j < n; ++j) {
        int best = -1;                
        
        for (int i = 1; i <= n; ++i) {
            if (!used[i]) {
                if (best == -1 || V[i][j] < V[best][j]) {
                    best = i;
                }                        
            }
        }

        assert(best != -1);
        used[best] = 1;

        if (j + 1 < n) {
            printf("%lld %lld\n", V[best][j].a, V[best][j].b);
        }

        perm.pb(best);
    }

    for (int x : perm) {
        printf("%d ", x);
    }
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from naan.cpp:4:
naan.cpp: In function 'void solve()':
naan.cpp:121:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         assert(V[i].size() == n);                        
                ~~~~~~~~~~~~^~~~
naan.cpp:86:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~
naan.cpp:92:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%lld", &arr[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 408 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 504 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 6 ms 504 KB Output is correct
22 Correct 6 ms 508 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 6 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 408 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 380 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 6 ms 504 KB Output is correct
25 Correct 6 ms 504 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 6 ms 504 KB Output is correct
30 Correct 6 ms 504 KB Output is correct
31 Correct 6 ms 504 KB Output is correct
32 Correct 6 ms 504 KB Output is correct
33 Correct 6 ms 504 KB Output is correct
34 Correct 6 ms 504 KB Output is correct
35 Correct 6 ms 504 KB Output is correct
36 Correct 6 ms 504 KB Output is correct
37 Correct 6 ms 508 KB Output is correct
38 Correct 5 ms 376 KB Output is correct
39 Correct 6 ms 376 KB Output is correct
40 Correct 5 ms 376 KB Output is correct
41 Correct 5 ms 376 KB Output is correct
42 Correct 6 ms 376 KB Output is correct
43 Correct 55 ms 11896 KB Output is correct
44 Correct 313 ms 54140 KB Output is correct
45 Correct 209 ms 25464 KB Output is correct
46 Correct 36 ms 3576 KB Output is correct
47 Correct 253 ms 35064 KB Output is correct
48 Correct 203 ms 76664 KB Output is correct
49 Correct 89 ms 22776 KB Output is correct
50 Correct 375 ms 95480 KB Output is correct
51 Correct 215 ms 41720 KB Output is correct
52 Correct 430 ms 84216 KB Output is correct
53 Correct 318 ms 80248 KB Output is correct
54 Correct 6 ms 504 KB Output is correct
55 Correct 87 ms 44280 KB Output is correct
56 Correct 270 ms 56188 KB Output is correct
57 Correct 221 ms 49272 KB Output is correct
58 Correct 294 ms 78712 KB Output is correct
59 Correct 260 ms 46200 KB Output is correct
60 Correct 681 ms 100216 KB Output is correct
61 Correct 671 ms 99960 KB Output is correct
62 Correct 682 ms 99832 KB Output is correct
63 Correct 677 ms 100216 KB Output is correct
64 Correct 693 ms 100216 KB Output is correct
65 Correct 534 ms 99960 KB Output is correct
66 Correct 536 ms 99960 KB Output is correct
67 Correct 532 ms 99960 KB Output is correct
68 Correct 269 ms 58488 KB Output is correct
69 Correct 312 ms 52896 KB Output is correct
70 Correct 302 ms 69752 KB Output is correct
71 Correct 451 ms 75128 KB Output is correct