Submission #534996

#TimeUsernameProblemLanguageResultExecution timeMemory
534996radalNaan (JOI19_naan)C++17
24 / 100
2 ms332 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]; int cmp(pll x,pll y){ ll f1 = x.X*(y.Y/n) ,f2 = y.X * (x.Y/n); if (f1 == f2) return 0; if (f1 < f2) return 1; return -1; } 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]; } ll cur = 0; int k = 0; rep(j,0,n){ for (;cur + a[i][k]*n <= sum[i]*(j+1) && k < l; k++) cur += a[i][k]*n; if (k >= l) nxt[i][j] = {l,1}; else nxt[i][j] = {sum[i]*(j+1)+k*a[i][k]*n-cur,a[i][k]*n}; } } vector<int> ans; vector<pll> out; rep(g,0,n-1){ pll mi = {inf,1}; int j = 0; rep(i,0,n){ if (mark[i]) continue; if (cmp(mi,nxt[i][g]) == -1){ mi = nxt[i][g]; j = i; } } ans.pb(j+1); out.pb(mi); mark[j] = 1; } 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...