Submission #590282

#TimeUsernameProblemLanguageResultExecution timeMemory
590282perchutsNaan (JOI19_naan)C++17
100 / 100
445 ms116332 KiB
#include <bits/stdc++.h> #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' #define pb push_back #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); #define f first #define s second #define int ll using namespace std; using ll = long long; using ull = unsigned long long; using ii = pair<int,int>; using iii = tuple<int,int,int>; const int inf = 2e9+1; const int mod = 1e9+7; const int maxn = 2001; template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; } template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; } ll v[maxn][maxn], sum[maxn]; pair<ll,ll> d[maxn][maxn]; int p[maxn], pode[maxn]; bool menor(pair<ll,ll>a,pair<ll,ll>b){ if(a.f/a.s!=b.f/b.s)return a.f/a.s>b.f/b.s; return (a.f%a.s)*b.s > a.s*(b.f%b.s); } int32_t main(){_ ll n,l;cin>>n>>l; for(int i=1;i<=n;++i)for(int j=1;j<=l;++j)cin>>v[i][j], sum[i] += v[i][j]; for(int i=1;i<=n;++i){ ll atual = 1, act = 0; d[i][0] = {0,1}; for(int j=1;j<n;++j){ while(n*(act+v[i][atual])<=j*sum[i])act += v[i][atual++]; ll numerador = (sum[i]*j - act*n); ll denominador = n*v[i][atual]; numerador += denominador*(atual-1); d[i][j] = {numerador,denominador}; } } for(int i=1;i<=n;++i)pode[i] = 1; for(int i=1;i<n;++i){ pair<ll,ll>best = {-1,-1}; int idx = -1; for(int j=1;j<=n;++j){ if(pode[j]&&(best.f==-1||menor(best,d[j][i])))best = d[j][i], idx = j; } assert(idx!=-1); p[i] = idx, pode[idx] = 0; } for(int i=1;i<=n;++i)if(pode[i])p[n] = i; for(int i=1;i<n;++i)cout<<d[p[i]][i].f<<" "<<d[p[i]][i].s<<endl; for(int i=1;i<=n;++i)cout<<p[i]<<" \n"[i==n]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...