답안 #170165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170165 2019-12-24T06:30:23 Z gs18103 Naan (JOI19_naan) C++14
100 / 100
667 ms 149036 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define em emplace
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int MAX = 2020;
const int INF = (1 << 30) - 1;
const ll LINF = 1LL << 60;

int n, k, p[MAX];
ll v[MAX][MAX], sum[MAX][MAX];
pll X[MAX], dv[MAX][MAX];
bool chk[MAX];

bool small(pll x, pll y) {
    if(x.fi / x.se == y.fi / y.se) return (x.fi % x.se) * y.se > (y.fi % y.se) * x.se;
    else return x.fi / x.se > y.fi / y.se;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    //freopen("03-02.txt", "r", stdin);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k; j++) {
            cin >> v[i][j];
            sum[i][j] = sum[i][j-1] + v[i][j];
        }
        int idx = 0;
        for(int j = 1; j < n; j++) {
            while(sum[i][idx+1] * n <= sum[i][k] * j && idx < k) idx++;
            dv[i][j] = make_pair(sum[i][k] * j - sum[i][idx] * n, n * v[i][idx+1]);
            dv[i][j].fi += dv[i][j].se * idx;
        }
        dv[i][n] = make_pair(k, 1);
    }
    for(int i = 1; i <= n; i++) {
        int idx = -1;
        for(int j = 1; j <= n; j++) {
            if(chk[j]) continue;
            if(idx == -1 || small(dv[idx][i], dv[j][i])) {
                idx = j;
            }
        }
        chk[idx] = true;
        p[i] = idx;
        X[i] = dv[idx][i];
    }

    for(int i = 1; i < n; i++) {
        cout << X[i].fi << ' ' << X[i].se << endl;
    }
    for(int i = 1; i <= n; i++) {
        cout << p[i] << ' ';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 504 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 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 1 ms 504 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 560 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 632 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 632 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
16 Correct 3 ms 632 KB Output is correct
17 Correct 3 ms 632 KB Output is correct
18 Correct 4 ms 632 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 632 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 3 ms 632 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 3 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 504 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 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 2 ms 504 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 1 ms 504 KB Output is correct
19 Correct 3 ms 632 KB Output is correct
20 Correct 3 ms 560 KB Output is correct
21 Correct 2 ms 508 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 504 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 632 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 632 KB Output is correct
30 Correct 3 ms 632 KB Output is correct
31 Correct 3 ms 632 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 4 ms 632 KB Output is correct
34 Correct 3 ms 632 KB Output is correct
35 Correct 3 ms 632 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 3 ms 632 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 3 ms 632 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 504 KB Output is correct
42 Correct 3 ms 632 KB Output is correct
43 Correct 55 ms 17580 KB Output is correct
44 Correct 306 ms 75536 KB Output is correct
45 Correct 180 ms 39928 KB Output is correct
46 Correct 27 ms 6008 KB Output is correct
47 Correct 230 ms 57572 KB Output is correct
48 Correct 249 ms 90104 KB Output is correct
49 Correct 86 ms 31736 KB Output is correct
50 Correct 395 ms 123896 KB Output is correct
51 Correct 199 ms 58380 KB Output is correct
52 Correct 415 ms 114336 KB Output is correct
53 Correct 329 ms 105496 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 118 ms 50936 KB Output is correct
56 Correct 271 ms 77048 KB Output is correct
57 Correct 210 ms 67396 KB Output is correct
58 Correct 314 ms 101144 KB Output is correct
59 Correct 228 ms 64168 KB Output is correct
60 Correct 659 ms 148928 KB Output is correct
61 Correct 664 ms 148804 KB Output is correct
62 Correct 667 ms 148568 KB Output is correct
63 Correct 658 ms 148980 KB Output is correct
64 Correct 663 ms 149036 KB Output is correct
65 Correct 523 ms 135612 KB Output is correct
66 Correct 518 ms 135652 KB Output is correct
67 Correct 525 ms 135620 KB Output is correct
68 Correct 261 ms 78744 KB Output is correct
69 Correct 292 ms 76632 KB Output is correct
70 Correct 304 ms 92536 KB Output is correct
71 Correct 423 ms 107640 KB Output is correct