Submission #535006

#TimeUsernameProblemLanguageResultExecution timeMemory
535006radalNaan (JOI19_naan)C++17
24 / 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]; pll nxt[N][N]; bool mark[N]; int main(){ ios :: sync_with_stdio(0); cin.tie(0); cin >> n >> l; rep(i,0,n){ ll sum = 0; rep(j,0,l){ cin >> a[i][j]; sum += 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*j){ cur += a[i][k]; k++; } if (k == l) nxt[i][j] = {l,1}; else{ ll g; nxt[i][j] = {(sum*j-cur)+k*a[i][k],a[i][k]}; g = gcd(nxt[i][j].X,nxt[i][j].Y); nxt[i][j].X /= g; nxt[i][j].Y /= g; } } } auto cmp = [&] (pll x, pll y){return x.X * (y.Y/n) < (x.Y/n) * y.X;}; 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(); 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...