Submission #338908

# Submission time Handle Problem Language Result Execution time Memory
338908 2020-12-24T08:27:31 Z syy Naan (JOI19_naan) C++17
100 / 100
771 ms 137068 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;
		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 time Memory Grader output
1 Correct 1 ms 384 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 492 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 512 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 512 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 2 ms 492 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 2 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 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 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 492 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 512 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 512 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 2 ms 492 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 2 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 2 ms 492 KB Output is correct
43 Correct 62 ms 17900 KB Output is correct
44 Correct 396 ms 87156 KB Output is correct
45 Correct 173 ms 34028 KB Output is correct
46 Correct 25 ms 3820 KB Output is correct
47 Correct 242 ms 47212 KB Output is correct
48 Correct 526 ms 106860 KB Output is correct
49 Correct 127 ms 29932 KB Output is correct
50 Correct 659 ms 129104 KB Output is correct
51 Correct 254 ms 60652 KB Output is correct
52 Correct 591 ms 113772 KB Output is correct
53 Correct 524 ms 107500 KB Output is correct
54 Correct 1 ms 492 KB Output is correct
55 Correct 245 ms 67564 KB Output is correct
56 Correct 334 ms 78700 KB Output is correct
57 Correct 281 ms 70548 KB Output is correct
58 Correct 460 ms 105324 KB Output is correct
59 Correct 275 ms 66284 KB Output is correct
60 Correct 668 ms 129516 KB Output is correct
61 Correct 651 ms 129388 KB Output is correct
62 Correct 771 ms 128876 KB Output is correct
63 Correct 724 ms 129620 KB Output is correct
64 Correct 699 ms 129516 KB Output is correct
65 Correct 580 ms 137068 KB Output is correct
66 Correct 566 ms 137032 KB Output is correct
67 Correct 664 ms 137068 KB Output is correct
68 Correct 285 ms 83564 KB Output is correct
69 Correct 291 ms 78188 KB Output is correct
70 Correct 337 ms 97644 KB Output is correct
71 Correct 498 ms 107628 KB Output is correct