Submission #170118

#TimeUsernameProblemLanguageResultExecution timeMemory
170118gs18103Naan (JOI19_naan)C++14
29 / 100
38 ms10456 KiB
#include <bits/stdc++.h> #define fi first #define se second #define eb emplace_back #define em emplace #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const int MAX = 2020; const int INF = (1 << 30) - 1; const ll LINF = 1LL << 60; int n, k; ll v[MAX][MAX], sum[MAX][MAX], p[MAX]; pll X[MAX]; bool chk[MAX]; bool cal(int j, int m, pii st) { return (sum[j][m] - sum[j][st.fi/st.se]) * n * st.se <= sum[j][k] * st.se + (st.fi % st.se) * v[j][st.fi/st.se+1] * n; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++) { for(int j = 1; j <= k; j++) { cin >> v[i][j]; sum[i][j] = sum[i][j-1] + v[i][j]; } } pll st = make_pair(0, 1); for(int i = 1; i <= n; i++) { int idx = 0; pll mi = make_pair(k, 1); for(int j = 1; j <= n; j++) { if(chk[j]) continue; int lb = 0, ub = k; while(lb < ub) { int m = (lb + ub + 1) / 2; if(cal(j, m, st)) lb = m; else ub = m - 1; } pll temp = make_pair((sum[j][st.fi/st.se] - sum[j][lb]) * n * st.se + (st.fi % st.se) * v[j][st.fi/st.se+1] * n + sum[j][k] * st.se, n * st.se * v[j][lb+1]); if(lb == k) { if(temp.fi == 0) { temp = make_pair(0, 1); } else continue; } temp.fi += temp.se * lb; if(mi.fi * temp.se >= temp.fi * mi.se) mi = temp, idx = j; } if(idx == 0) return !(cout << -1); chk[idx] = true; p[i] = idx; ll g = __gcd(mi.fi, mi.se); mi.fi /= g, mi.se /= g; X[i] = mi; st = mi; } for(int i = 1; i < n; i++) { cout << X[i].fi << ' ' << X[i].se << endl; } for(int i = 1; i <= n; i++) { cout << p[i] << ' '; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...