Submission #338908

#TimeUsernameProblemLanguageResultExecution timeMemory
338908syyNaan (JOI19_naan)C++17
100 / 100
771 ms137068 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++) #define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--) typedef pair<ll, ll> pi; typedef pair<pi, ll> pii; typedef pair<ll, pi> ipi; typedef pair<pi, pi> pipi; #define mp make_pair #define f first #define s second typedef vector<ll> vi; typedef vector<pi> vpi; typedef vector<pii> vpii; #define pb push_back #define pf push_front #define all(v) v.begin(), v.end() #define size(v) (ll) v.size() #define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin()); #define INF (ll) 1e9 + 100 #define LLINF (ll) 1e18 #define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge"))) mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng) inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss struct frac { ll n, d; frac(ll x = 0, ll num = 0, ll den = 1) { // default to 0 assert(den != 0); // no divide by 0 n = num; d = den; n += x * d; } bool operator<(frac a) const { return (__int128) n*a.d < (__int128) a.n*d; } void print() { cout << n << " " << d << "\n"; } }; ll n, l, arr[2005][2005]; bool vis[2005]; vector<pair<frac, ll>> v[2005]; vi ans; int main() { fastio; cin >> n >> l; FOR(i, 1, n) FOR(j, 1, l) cin >> arr[i][j]; FOR(i, 1, n) { ll tot = 0; FOR(j, 1, l) tot += arr[i][j]; ll idx = 1, cur = 0; FOR(j, 1, n-1) { //find prefix of naan with j/n value while (idx <= l and n * (cur + arr[i][idx]) < j * tot) cur += arr[i][idx++]; v[j].pb(mp(frac(idx-1, j*tot - cur*n, n*arr[i][idx]), i)); } } FOR(i, 1, n-1) { sort(all(v[i])); ll idx = 0; while (vis[v[i][idx].s]) idx++; ans.pb(v[i][idx].s); vis[v[i][idx].s] = 1; v[i][idx].f.print(); } for (auto it:ans) cout << it << " "; cout << n * (n+1) / 2 - accumulate(all(ans), 0ll); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...