Submission #337466

# Submission time Handle Problem Language Result Execution time Memory
337466 2020-12-20T23:45:57 Z syy Naan (JOI19_naan) C++17
29 / 100
462 ms 78060 KB
#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;
		if (d < 0) d = -d, n = -n;
		n += x * d;
	}
	frac operator+(frac a) {
		return frac(0, n*a.d + a.n*d, d*a.d);
	}
	frac operator+(ll a) {
		return frac(0, n + a*d, d);
	}
	frac operator-() {
		return frac(0, -n, d);
	}
	frac operator-(frac a) {
		return frac(0, n*a.d - a.n*d, d*a.d);
	}
	frac operator-(ll a) {
		return frac(0, n - a*d, d);
	}
	frac operator*(frac a) {
		return frac(0, n*a.n, d*a.d);
	}
	frac operator*(ll a) {
		return frac(0, n*a, d);
	}
	frac operator/(frac a) {
		return frac(0, n*a.d, a.n*d);
	}
	frac operator/(ll a) {
		return frac(0, n, a*d);
	}
	bool operator>(ll a) {
		return n > a*d;
	}
	bool operator<(frac a) const {
		return n*a.d < 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;

bool cmp(pair<frac, ll> a, pair<frac, ll> b) {
	return a.f < b.f;
}

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 = 0, cur = 0;
		FOR(j, 1, n-1) { //find prefix of naan with j/n value
			while (idx < l and frac(0, j*tot, n) > cur + arr[i][idx+1]) cur += arr[i][++idx];
			v[j].pb(mp(((frac(0, j*tot, n) - cur) / arr[i][idx+1]) + idx, i));
		}
	}
	FOR(i, 1, n-1) {
		sort(all(v[i]), cmp);
		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 << " ";
	FOR(i, 1, n) if (!vis[i]) cout << i;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 492 KB Output is correct
17 Correct 1 ms 500 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 492 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 1 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 492 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 492 KB Output is correct
24 Correct 1 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 1 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 492 KB Output is correct
29 Correct 1 ms 492 KB Output is correct
30 Correct 1 ms 492 KB Output is correct
31 Correct 1 ms 492 KB Output is correct
32 Correct 1 ms 500 KB Output is correct
33 Correct 1 ms 492 KB Output is correct
34 Correct 1 ms 492 KB Output is correct
35 Correct 1 ms 492 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 492 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 492 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 1 ms 492 KB Output is correct
42 Correct 1 ms 492 KB Output is correct
43 Correct 75 ms 17004 KB Output is correct
44 Incorrect 462 ms 78060 KB X_i is not increasing
45 Halted 0 ms 0 KB -