답안 #131748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
131748 2019-07-17T14:19:45 Z IOrtroiii Naan (JOI19_naan) C++14
29 / 100
147 ms 11724 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Val = array<ll, 3>;

Val make(ll x, ll y, ll z) {
   ll g = __gcd(y, z);
   y /= g, z /= g;
   return {x, y, z};
}

bool cmp(Val l, Val r) {
   if (l[0] ^ r[0]) {
      return l[0] < r[0];
   } else {
      return l[0] * r[1] < l[1] * r[0];
   }
}

int main() {
   ios_base::sync_with_stdio(false);
   int n, l;
   cin >> n >> l;
   vector<vector<Val>> go(n);
   for (int i = 0; i < n; ++i) {
      ll sum = 0;
      vector<ll> a(l);
      for (int j = 0; j < l; ++j) {
         cin >> a[j];
         sum += a[j];
      }
      ll csum = 0;
      int cur = 0;
      for (int j = 1; j < n; ++j) {
         while (cur < l && (ll) (csum + a[cur]) * n <= (ll) sum * j) {
            csum += a[cur++];
         }
         go[i].push_back(make(cur, sum * j - csum * n, a[cur] * n));
      }
      go[i].push_back(make(l, 0, 1));
   }
   vector<Val> ans;
   vector<int> p;
   vector<bool> used(n, false);
   for (int i = 0; i < n; ++i) {
      int nxt = -1;
      for (int j = 0; j < n; ++j) {
         if (used[j]) continue;
         if (nxt == -1 || cmp(go[j][i], go[nxt][i])) {
            nxt = j;
         }
      }
      used[nxt] = true;
      ans.push_back(go[nxt][i]);
      p.push_back(nxt);
   }
   ans.pop_back();
   for (auto v : ans) {
      cout << v[0] * v[2] + v[1] << " " << v[2] << "\n";
   }
   for (int v : p) {
      cout << v + 1 << " ";
   }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 4 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 388 KB Output is correct
3 Correct 2 ms 376 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 3 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 380 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 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 2 ms 380 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 4 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 388 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 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 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 380 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 3 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 3 ms 376 KB Output is correct
41 Correct 2 ms 380 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Incorrect 147 ms 11724 KB X_i is not increasing
44 Halted 0 ms 0 KB -