답안 #337422

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337422 2020-12-20T16:23:03 Z ryangohca Naan (JOI19_naan) C++17
100 / 100
435 ms 95468 KB
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
using namespace std;
 
int nums[2000][2000];
pii cuts[2000][2000];
vector<pii> confirmed;
vector<int> order;
bool ordered[2000];
inline int read() {
    int g; cin >> g;
    return g;
}
main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n = read(), l = read();
    for (int i = 0; i < n; i++){
        int need = 0;
        for (int j = 0; j < l; j++){
            cin >> nums[i][j]; nums[i][j] *= n;
            need += nums[i][j];
        }
        need /= n;
        cuts[i][0] = {0, 0};
        int idxwhole = 0, idxpart = 0;
        int curr = 0;
        for (int j = 1; j < n; j++){
            while (need > curr){
                int willtake = nums[i][idxwhole] - idxpart;
                if (curr + willtake <= need){
                    curr += willtake;
                    idxwhole++;
                    idxpart = 0;
                } else {
                    idxpart += need - curr;
                    curr = need;
                }
            }
            cuts[i][j] = pii(idxwhole*nums[i][idxwhole]+idxpart, nums[i][idxwhole]);
            curr = 0;
        }
    }
    for (int i = 1; i < n; i++){
        auto take = pair<pii, int>({1e9, 1}, -1);
        for (int j = 0; j < n; j++){
            if (ordered[j]) continue;
            pii curr = cuts[j][i];
            if ((__int128_t)take.first.first * curr.second - (__int128_t) take.first.second * curr.first <= 0) continue;
            take = {curr, j};
        }
        ordered[take.second] = true;
        confirmed.push_back({take.first.first, take.first.second});
        order.push_back(take.second);
    }
    for (int i = 0; i < n; i++){
        if (!ordered[i]) order.push_back(i);
    }
    for (auto [a, b] : confirmed){
        int f = __gcd(a, b);
        cout << a/f << ' ' << b/f << '\n';
    }
    for (auto i : order) cout << i + 1 << ' ';
    cout << endl;
}

Compilation message

naan.cpp:15:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   15 | main(){
      |      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 368 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 0 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 496 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 0 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 512 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 368 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 0 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 496 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 2 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 0 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 364 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 32 ms 11904 KB Output is correct
44 Correct 197 ms 53996 KB Output is correct
45 Correct 126 ms 21504 KB Output is correct
46 Correct 21 ms 2924 KB Output is correct
47 Correct 148 ms 34668 KB Output is correct
48 Correct 127 ms 73196 KB Output is correct
49 Correct 50 ms 23020 KB Output is correct
50 Correct 243 ms 90144 KB Output is correct
51 Correct 132 ms 38892 KB Output is correct
52 Correct 266 ms 81004 KB Output is correct
53 Correct 207 ms 77124 KB Output is correct
54 Correct 1 ms 492 KB Output is correct
55 Correct 50 ms 44012 KB Output is correct
56 Correct 169 ms 53200 KB Output is correct
57 Correct 136 ms 46956 KB Output is correct
58 Correct 183 ms 75628 KB Output is correct
59 Correct 157 ms 42988 KB Output is correct
60 Correct 416 ms 94444 KB Output is correct
61 Correct 418 ms 94316 KB Output is correct
62 Correct 435 ms 94240 KB Output is correct
63 Correct 430 ms 94444 KB Output is correct
64 Correct 414 ms 94436 KB Output is correct
65 Correct 319 ms 95340 KB Output is correct
66 Correct 325 ms 95468 KB Output is correct
67 Correct 330 ms 95468 KB Output is correct
68 Correct 159 ms 55152 KB Output is correct
69 Correct 192 ms 50028 KB Output is correct
70 Correct 180 ms 66284 KB Output is correct
71 Correct 274 ms 71788 KB Output is correct