Submission #535004

#TimeUsernameProblemLanguageResultExecution timeMemory
535004radalNaan (JOI19_naan)C++17
0 / 100
2 ms352 KiB
#include <bits/stdc++.h> #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define X first #define Y second #define pb push_back #define endl '\n' #define debug(x) cerr << #x << " : " << x << endl; using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; constexpr ll N = 2e3+20,mod = 1e9+7,inf = 1e18+10,maxm = 1e6; inline int mkay(int a,int b){ if (a+b >= mod) return a+b-mod; if (a+b < 0) return a+b+mod; return a+b; } inline int poww(int a,int k){ if (k < 0) return 0; int z = 1; while (k){ if (k&1) z = 1ll*z*a%mod; a = 1ll*a*a%mod; k >>= 1; } return z; } int n,l; ll a[N][N],sum[N]; pll nxt[N][N]; bool mark[N]; bool cmp(pll x,pll y){ ll f1 = x.X*(y.Y/n) ,f2 = y.X * (x.Y/n); if (f1 < f2) return 1; return 0; } int main(){ ios :: sync_with_stdio(0); cin.tie(0); cin >> n >> l; rep(i,0,n){ rep(j,0,l){ cin >> a[i][j]; sum[i] += a[i][j]; a[i][j] *= n; } ll cur = 0; int k = 0; rep(j,1,n+1){ while (k < l && cur+a[i][k] <= sum[i]*j){ cur += a[i][k]; k++; } if (k == l) nxt[i][j] = {l,1}; else nxt[i][j] = {-cur+sum[i]*j+k*a[i][k],a[i][k]}; } } vector<int> ans; vector<pll> out; rep(g,1,n+1){ pll mi = {inf,1}; int j = 0; rep(i,0,n){ if (mark[i]) continue; if (cmp(mi,nxt[i][g]) == 0){ mi = nxt[i][g]; j = i; } } ans.pb(j+1); out.pb(mi); mark[j] = 1; } out.pop_back(); rep(i,0,n) if (!mark[i]) ans.pb(i+1); for (pll p : out){ ll g = gcd(p.X,p.Y); cout << p.X/g << ' ' << p.Y/g << endl; } for (int u : ans) cout << u << ' '; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...