제출 #508846

#제출 시각아이디문제언어결과실행 시간메모리
508846couplefireNaan (JOI19_naan)C++17
100 / 100
345 ms100976 KiB
#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';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...