답안 #162930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
162930 2019-11-10T10:11:44 Z combi1k1 Naan (JOI19_naan) C++14
100 / 100
1810 ms 134792 KB
#include<bits/stdc++.h>

using namespace std;

#define ll  long long
#define pb  push_back

#define FOR(i,a,b)  for(int i = a ; i < b ; ++i)

const int   N   = 2e3 + 1;
const int   inf = 1e9 + 7;

struct Frac {
    ll  int_part;
    ll  upper;
    ll  lower;

    Frac(ll a = 0,ll b = 0,ll c = 0)    {
        int_part = a;
        upper = b;
        lower = c;
        if (b > c)  {
            int_part += b / c;
            upper %= c;
        }
        ll  g = __gcd(abs(b),abs(c));
        upper /= g;
        lower /= g;

        if (c < 0)
            upper *= (-1),
            lower *= (-1);
    };
};
bool operator < (const Frac &lhs,const Frac &rhs)   {
    if (lhs.int_part != rhs.int_part)
        return  lhs.int_part < rhs.int_part;

    return  lhs.upper * rhs.lower < lhs.lower * rhs.upper;
}
ostream & operator << (ostream &out,Frac &C)    {
    ll  a = C.int_part * C.lower + C.upper;
    ll  b = C.lower;

    out << a << " ";
    out << b << "\n";
    return  out;
}

int v[N][N];
ll  s[N];

vector<Frac> cut[N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;
    int L;  cin >> L;

    FOR(i,0,n)  FOR(j,0,L)  {
        cin >>  v[i][j];
        s[i] += v[i][j];
    }

    FOR(i,0,n)  {
        ll  sum = 0;
        int ptr = 0;

        FOR(j,1,n)  {
            for(; (sum +  v[i][ptr]) * n <= s[i] * j ; ++ptr)
                   sum += v[i][ptr];

            ll  lower = v[i][ptr] * n;
            ll  upper = s[i] * j - sum * n;

            cut[i].pb({ptr,upper,lower});
        }
        cut[i].pb({L,0,1});
    }

    vector<int> perm;
    vector<int> have;

    FOR(i,0,n)  have.push_back(i);
    FOR(i,0,n)  {
        sort(have.begin(),have.end(),[&](int x,int y)   {
            return  cut[y][i] < cut[x][i];
        });
        perm.push_back(have.back());
        have.pop_back();

        if (i < n - 1)  cout << cut[perm.back()][i];
    }
    for(int x : perm)   cout << x + 1 << " ";
}
/*
2 5
2 7 1 8 2
3 1 4 1 5
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 476 KB Output is correct
12 Correct 3 ms 484 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 508 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 380 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 632 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 476 KB Output is correct
12 Correct 3 ms 484 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 504 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 504 KB Output is correct
36 Correct 3 ms 508 KB Output is correct
37 Correct 3 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 3 ms 380 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 436 KB Output is correct
43 Correct 165 ms 15028 KB Output is correct
44 Correct 972 ms 70492 KB Output is correct
45 Correct 328 ms 27200 KB Output is correct
46 Correct 29 ms 2808 KB Output is correct
47 Correct 555 ms 40000 KB Output is correct
48 Correct 1467 ms 103400 KB Output is correct
49 Correct 317 ms 27948 KB Output is correct
50 Correct 1743 ms 116364 KB Output is correct
51 Correct 555 ms 42076 KB Output is correct
52 Correct 1394 ms 96932 KB Output is correct
53 Correct 1293 ms 92048 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 737 ms 59176 KB Output is correct
56 Correct 808 ms 59536 KB Output is correct
57 Correct 629 ms 52472 KB Output is correct
58 Correct 1173 ms 92604 KB Output is correct
59 Correct 597 ms 47476 KB Output is correct
60 Correct 1538 ms 134432 KB Output is correct
61 Correct 1563 ms 134332 KB Output is correct
62 Correct 1792 ms 133960 KB Output is correct
63 Correct 1664 ms 134792 KB Output is correct
64 Correct 1617 ms 134400 KB Output is correct
65 Correct 1790 ms 121264 KB Output is correct
66 Correct 1810 ms 121064 KB Output is correct
67 Correct 1572 ms 121104 KB Output is correct
68 Correct 622 ms 67832 KB Output is correct
69 Correct 575 ms 59104 KB Output is correct
70 Correct 818 ms 83792 KB Output is correct
71 Correct 947 ms 89844 KB Output is correct