답안 #508846

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
508846 2022-01-13T22:04:28 Z couplefire Naan (JOI19_naan) C++17
100 / 100
345 ms 100976 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;
 
mt19937 rng( (uint32_t)chrono::steady_clock::now().time_since_epoch().count() );
 
int main() {
  cin.tie(0)->sync_with_stdio(0);
 
  int n, L; cin >> n >> L;
  vector<vector<int> > v(n, vector<int>(L) );
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < L; ++j) cin >> v[i][j];
  }
 
  vector<vector<pair<LL, int> > > cut(n, vector<pair<LL, int> >(n) );
  for (int i = 0; i < n; ++i) {
    int sum = accumulate(all(v[i]), 0);
    int cur = 0, pter = 0;
    for (int j = 0; j < n; ++j) {
      while ( (LL)cur * n < (LL)sum * (j + 1)) cur += v[i][pter++];
      cut[i][j] = { (LL)pter * n * v[i][pter - 1] - (LL)cur * n + (LL)sum * (j + 1), n * v[i][pter - 1] };
    }
  }
 
  auto smaller = [&](const pair<LL, int> &a, const pair<LL, int> &b) {
    return (double)a.first / a.second < (double)b.first / b.second;
  };
  vector<bool> inAns(n, false);
  vector<int> ans;
  for (int i = 0; i < n; ++i) {
    int choo = -1;
    for (int j = 0; j < n; ++j) if (!inAns[j]) {
      if (choo == -1 || smaller(cut[j][i], cut[choo][i]) ) choo = j;
    }
    ans.emplace_back(choo); inAns[ans.back()] = true;
  }
 
  for (int i = 0; i < n - 1; ++i) cout << cut[ ans[i] ][i].first << ' ' << cut[ ans[i] ][i].second << '\n';
  for (int i : ans) cout << i + 1 << ' ';
  cout << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 376 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 388 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 264 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 380 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 0 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 304 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 0 ms 320 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 324 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 376 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 320 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 388 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 264 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 380 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 328 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 320 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 320 KB Output is correct
41 Correct 0 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 24 ms 7860 KB Output is correct
44 Correct 158 ms 46240 KB Output is correct
45 Correct 100 ms 20292 KB Output is correct
46 Correct 14 ms 2344 KB Output is correct
47 Correct 122 ms 29156 KB Output is correct
48 Correct 96 ms 60644 KB Output is correct
49 Correct 36 ms 15172 KB Output is correct
50 Correct 173 ms 76768 KB Output is correct
51 Correct 99 ms 27808 KB Output is correct
52 Correct 194 ms 66112 KB Output is correct
53 Correct 151 ms 58648 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 36 ms 32196 KB Output is correct
56 Correct 124 ms 39480 KB Output is correct
57 Correct 97 ms 33032 KB Output is correct
58 Correct 132 ms 57360 KB Output is correct
59 Correct 116 ms 32320 KB Output is correct
60 Correct 345 ms 100976 KB Output is correct
61 Correct 331 ms 100548 KB Output is correct
62 Correct 333 ms 100284 KB Output is correct
63 Correct 339 ms 100808 KB Output is correct
64 Correct 340 ms 100764 KB Output is correct
65 Correct 261 ms 87316 KB Output is correct
66 Correct 260 ms 87448 KB Output is correct
67 Correct 260 ms 87648 KB Output is correct
68 Correct 128 ms 42632 KB Output is correct
69 Correct 146 ms 40656 KB Output is correct
70 Correct 146 ms 52640 KB Output is correct
71 Correct 210 ms 63048 KB Output is correct