Submission #410196

# Submission time Handle Problem Language Result Execution time Memory
410196 2021-05-22T09:02:55 Z amoo_safar Naan (JOI19_naan) C++17
100 / 100
557 ms 91332 KB
// vaziat meshki-ghermeze !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 2e5 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

typedef pll frac;

bool CMP(frac A, frac B){
	ll cA = A.F / A.S;
	ll cB = B.F / B.S;
	if(cA != cB)
		return cA < cB;
	return (A.F % A.S) * B.S < A.S * (B.F % B.S);
}

ll V[N];
vector<frac> cut[N];
int mk[N];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, L;
	cin >> n >> L;

	for(int p = 0; p < n; p++){
		ll sm = 0;
		for(int i = 0; i < L; i++){
			cin >> V[i];
			sm += V[i];
		}
		int po = 0;
		ll smnw = 0;
		for(int it = 1; it < n; it ++){
			while(n * (V[po] + smnw) <= sm * it){
				smnw += V[po];
				po ++;
			}
			frac alp = frac(it * sm - smnw * n, n * V[po]); 
			frac bet = frac(alp.F + po * alp.S, alp.S);
			cut[p].pb(bet);
		}
		// cerr << p << " : ";
		// for(auto [up, dw] : cut[p]) cerr << up << "/" << dw << '\n';
		// cerr << '\n';
	}
	vector<int> P;
	for(int i = 0; i < n - 1; i++){
		int idx = -1;
		for(int j = 0; j < n; j++){
			if(mk[j])continue;
			if(idx == -1) idx = j;
			if(CMP(cut[j][i], cut[idx][i]))
				idx = j;
		}
		mk[idx] = 1;
		cout << cut[idx][i].F << ' ' << cut[idx][i].S << '\n';
		P.pb(idx + 1);
	}
	for(int i = 0; i < n; i++) if(!mk[i]) P.pb(i + 1);
	for(auto x : P) cout << x << ' ';
	cout << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5064 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4984 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 5036 KB Output is correct
12 Correct 5 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4940 KB Output is correct
2 Correct 3 ms 4940 KB Output is correct
3 Correct 5 ms 5032 KB Output is correct
4 Correct 5 ms 4940 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 4 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 5 ms 4940 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 5044 KB Output is correct
19 Correct 5 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 4 ms 4940 KB Output is correct
23 Correct 3 ms 4940 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 4 ms 4940 KB Output is correct
26 Correct 4 ms 4940 KB Output is correct
27 Correct 4 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5064 KB Output is correct
2 Correct 4 ms 4940 KB Output is correct
3 Correct 4 ms 4940 KB Output is correct
4 Correct 3 ms 4984 KB Output is correct
5 Correct 4 ms 4940 KB Output is correct
6 Correct 4 ms 4940 KB Output is correct
7 Correct 3 ms 4940 KB Output is correct
8 Correct 4 ms 4940 KB Output is correct
9 Correct 4 ms 4940 KB Output is correct
10 Correct 4 ms 4940 KB Output is correct
11 Correct 4 ms 5036 KB Output is correct
12 Correct 5 ms 4940 KB Output is correct
13 Correct 4 ms 4940 KB Output is correct
14 Correct 4 ms 4940 KB Output is correct
15 Correct 4 ms 4940 KB Output is correct
16 Correct 4 ms 4940 KB Output is correct
17 Correct 3 ms 4940 KB Output is correct
18 Correct 5 ms 5032 KB Output is correct
19 Correct 5 ms 4940 KB Output is correct
20 Correct 4 ms 4940 KB Output is correct
21 Correct 4 ms 4940 KB Output is correct
22 Correct 3 ms 4940 KB Output is correct
23 Correct 4 ms 4940 KB Output is correct
24 Correct 4 ms 4940 KB Output is correct
25 Correct 4 ms 4940 KB Output is correct
26 Correct 4 ms 4940 KB Output is correct
27 Correct 4 ms 4940 KB Output is correct
28 Correct 4 ms 4940 KB Output is correct
29 Correct 4 ms 4940 KB Output is correct
30 Correct 4 ms 4940 KB Output is correct
31 Correct 5 ms 4940 KB Output is correct
32 Correct 4 ms 4940 KB Output is correct
33 Correct 4 ms 5044 KB Output is correct
34 Correct 5 ms 4940 KB Output is correct
35 Correct 4 ms 4940 KB Output is correct
36 Correct 4 ms 4940 KB Output is correct
37 Correct 4 ms 4940 KB Output is correct
38 Correct 3 ms 4940 KB Output is correct
39 Correct 4 ms 4940 KB Output is correct
40 Correct 4 ms 4940 KB Output is correct
41 Correct 4 ms 4940 KB Output is correct
42 Correct 4 ms 4940 KB Output is correct
43 Correct 39 ms 12116 KB Output is correct
44 Correct 250 ms 39856 KB Output is correct
45 Correct 148 ms 22652 KB Output is correct
46 Correct 26 ms 6372 KB Output is correct
47 Correct 204 ms 28940 KB Output is correct
48 Correct 169 ms 66952 KB Output is correct
49 Correct 63 ms 19988 KB Output is correct
50 Correct 307 ms 73796 KB Output is correct
51 Correct 184 ms 29964 KB Output is correct
52 Correct 348 ms 64768 KB Output is correct
53 Correct 271 ms 61296 KB Output is correct
54 Correct 5 ms 4992 KB Output is correct
55 Correct 79 ms 42064 KB Output is correct
56 Correct 241 ms 40744 KB Output is correct
57 Correct 169 ms 35904 KB Output is correct
58 Correct 240 ms 61044 KB Output is correct
59 Correct 201 ms 33396 KB Output is correct
60 Correct 515 ms 91072 KB Output is correct
61 Correct 557 ms 91148 KB Output is correct
62 Correct 552 ms 90944 KB Output is correct
63 Correct 520 ms 91332 KB Output is correct
64 Correct 538 ms 91176 KB Output is correct
65 Correct 437 ms 77936 KB Output is correct
66 Correct 435 ms 77904 KB Output is correct
67 Correct 455 ms 77768 KB Output is correct
68 Correct 219 ms 46512 KB Output is correct
69 Correct 246 ms 41724 KB Output is correct
70 Correct 237 ms 56520 KB Output is correct
71 Correct 351 ms 61936 KB Output is correct