답안 #201356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201356 2020-02-10T10:05:35 Z BThero Naan (JOI19_naan) C++17
0 / 100
7 ms 632 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) {}                
};         

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

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;
        }

        Ratio r(0, 1);

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

            while (X > 0) {
                if (cur + X > mean) {
                    r += Ratio(mean - cur, arr[i][j]);
                    X -= (mean - cur);
                    cur = mean;                    
                }
                else {
                    cur += X;
                    r += Ratio(X, arr[i][j]);
                    X = 0;
                }

                if (cur == mean) {
                    V[i].pb(r);
                    cur = 0;
                }
            }                    
        }

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

    Ratio cur(0, 1);
    vector<int> perm;

    for (int i = 1; i <= n; ++i) {
        int best = -1;
        
        for (int j = 1; j <= n; ++j) {
            if (!used[j]) {
                while (V[j][ptr[j]] <= cur) {
                    ++ptr[j];
                }

                if (best == -1 || V[j][ptr[j]] < V[best][ptr[best]]) {
                    best = j;                                        
                }
            }
        }

        used[best] = 1;
        perm.pb(best);
        Ratio nxt = V[best][ptr[best]];
        
        if (i < n) {
            printf("%lld %lld\n", nxt.a, nxt.b);
        }

        cur = nxt;
    }

    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:115:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         assert(V[i].size() == n);                        
                ~~~~~~~~~~~~^~~~
naan.cpp:80: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:86: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 380 KB Output is correct
2 Runtime error 7 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Incorrect 6 ms 504 KB Not a fair distribution.
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Runtime error 7 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -