답안 #290620

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290620 2020-09-04T07:50:53 Z PeppaPig Naan (JOI19_naan) C++14
100 / 100
819 ms 116728 KB
#include <bits/stdc++.h>

#define long long long

using namespace std;

const int N = 2e3 + 5;

struct Fraction {
    long x, y;
    Fraction() {}
    Fraction(long x, long y) : x(x), y(y) {}
    friend bool operator<(const Fraction &a, const Fraction &b) {
        if(a.x / a.y != b.x / b.y) return a.x / a.y < b.x / b.y;
        return (a.x % a.y) * b.y < (b.x % b.y) * a.y;
    }
} pos[N][N];

int n, m;
int ans[N], chk[N];
long v[N][N];

Fraction get_pos(int idx, long x, long y) {
    int l = 1, r = m;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(v[idx][mid] * y > x) r = mid;
        else l = mid + 1;
    }
    x -= v[idx][r - 1] * y;
    y *= (v[idx][r] - v[idx][r - 1]);
    x += (r - 1) * y;
    return Fraction(x, y);
}

int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            scanf("%lld", v[i] + j);
            v[i][j] += v[i][j - 1];
        }
        for(int j = 1; j <= n; j++)
            pos[i][j] = get_pos(i, 1ll * j * v[i][m], n);
    }
    for(int i = 1; i <= n; i++) {
        int nex = -1;
        for(int j = 1; j <= n; j++) if(!chk[j] && (nex == -1 || pos[j][i] < pos[nex][i]))
            nex = j;
        ans[i] = nex, chk[nex] = 1;
        if(i < n)
            printf("%lld %lld\n", pos[nex][i].x, pos[nex][i].y);
    }
    for(int i = 1; i <= n; i++) printf("%d ", ans[i]);
    printf("\n");

    return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
naan.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |             scanf("%lld", v[i] + j);
      |             ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 512 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 512 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 2 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 2 ms 512 KB Output is correct
37 Correct 2 ms 512 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 1 ms 512 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 1 ms 384 KB Output is correct
42 Correct 1 ms 384 KB Output is correct
43 Correct 56 ms 13432 KB Output is correct
44 Correct 382 ms 63864 KB Output is correct
45 Correct 221 ms 28920 KB Output is correct
46 Correct 33 ms 4088 KB Output is correct
47 Correct 284 ms 42488 KB Output is correct
48 Correct 232 ms 75256 KB Output is correct
49 Correct 83 ms 24056 KB Output is correct
50 Correct 405 ms 95608 KB Output is correct
51 Correct 219 ms 41592 KB Output is correct
52 Correct 449 ms 87160 KB Output is correct
53 Correct 368 ms 80888 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 82 ms 44024 KB Output is correct
56 Correct 277 ms 56440 KB Output is correct
57 Correct 213 ms 49368 KB Output is correct
58 Correct 317 ms 78584 KB Output is correct
59 Correct 249 ms 46200 KB Output is correct
60 Correct 796 ms 116472 KB Output is correct
61 Correct 819 ms 116444 KB Output is correct
62 Correct 798 ms 116344 KB Output is correct
63 Correct 789 ms 116728 KB Output is correct
64 Correct 798 ms 116600 KB Output is correct
65 Correct 536 ms 103160 KB Output is correct
66 Correct 541 ms 103288 KB Output is correct
67 Correct 560 ms 103288 KB Output is correct
68 Correct 303 ms 60280 KB Output is correct
69 Correct 345 ms 56568 KB Output is correct
70 Correct 368 ms 72184 KB Output is correct
71 Correct 507 ms 82296 KB Output is correct