답안 #524363

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
524363 2022-02-09T06:18:24 Z AmShZ Naan (JOI19_naan) C++11
100 / 100
360 ms 101092 KB
//khodaya khodet komak kon
# include <bits/stdc++.h>

using namespace std;

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1
# define fast_io                                         ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 2e3 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const ld eps = 1e-15;
const int mod = 998244353;
const int base = 257;

int n, L, a[xn][xn], P[xn];
pll b[xn][xn];
bool mark[xn];

bool cmp(pll x, pll y){
	ld X = ld(x.A) / ld(x.B);
	ld Y = ld(y.A) / ld(y.B);
	return X <= Y;
}

int main(){
	fast_io;

	cin >> n >> L;
	for (int i = 1; i <= n; ++ i){
		int sum = 0;
		for (int j = 1; j <= L; ++ j)
			cin >> a[i][j], sum += a[i][j];
		int ptr = 0, last = 0;
		for (int j = 1; j <= n; ++ j){
			int res = sum;
			while (res){
				if (a[i][ptr + 1] * n - last < res){
					res -= a[i][ptr + 1] * n - last;
					++ ptr, last = 0;
					continue;
				}
				last += res, res = 0;
				int magh = a[i][ptr + 1] * n;
				b[i][j] = {1ll * ptr * magh + last, magh};
				if (last == a[i][ptr + 1] * n)
					++ ptr, last = 0;
			}
		}
	}
	for (int i = 1; i <= n; ++ i){
		int ind = - 1;
		pll mn = {inf, 1};
		for (int j = 1; j <= n; ++ j)
			if (!mark[j] && cmp(b[j][i], mn))
				mn = b[j][i], ind = j;
		mark[ind] = true, P[i] = ind;
		if (i < n)
			cout << mn.A << sep << mn.B << endl;
	}
	for (int i = 1; i <= n; ++ i)
		cout << P[i] << sep;
	cout << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 448 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 392 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 448 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 392 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 0 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 27 ms 10808 KB Output is correct
44 Correct 167 ms 55620 KB Output is correct
45 Correct 103 ms 23364 KB Output is correct
46 Correct 16 ms 3020 KB Output is correct
47 Correct 123 ms 35224 KB Output is correct
48 Correct 92 ms 72004 KB Output is correct
49 Correct 47 ms 22068 KB Output is correct
50 Correct 176 ms 83320 KB Output is correct
51 Correct 106 ms 33424 KB Output is correct
52 Correct 219 ms 73552 KB Output is correct
53 Correct 153 ms 69532 KB Output is correct
54 Correct 1 ms 332 KB Output is correct
55 Correct 42 ms 43332 KB Output is correct
56 Correct 124 ms 46228 KB Output is correct
57 Correct 100 ms 40644 KB Output is correct
58 Correct 133 ms 69700 KB Output is correct
59 Correct 116 ms 37244 KB Output is correct
60 Correct 342 ms 100808 KB Output is correct
61 Correct 346 ms 100828 KB Output is correct
62 Correct 334 ms 100596 KB Output is correct
63 Correct 341 ms 101092 KB Output is correct
64 Correct 360 ms 100928 KB Output is correct
65 Correct 267 ms 87728 KB Output is correct
66 Correct 262 ms 87596 KB Output is correct
67 Correct 259 ms 87624 KB Output is correct
68 Correct 127 ms 52548 KB Output is correct
69 Correct 161 ms 46752 KB Output is correct
70 Correct 169 ms 64180 KB Output is correct
71 Correct 219 ms 69728 KB Output is correct