답안 #118857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118857 2019-06-19T23:57:00 Z tmwilliamlin168 Naan (JOI19_naan) C++14
100 / 100
552 ms 147892 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long

const int mxN=2e3;
int n, l, m, p[mxN], b[mxN];
ll v[mxN][mxN];
array<ll, 3> a[mxN][mxN+1], a1[mxN];

bool cmp(array<ll, 3> a, array<ll, 3> b) {
	return a[0]^b[0]?a[0]<b[0]:a[1]*b[2]<b[1]*a[2];
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> l;
	for(int i=0; i<n; ++i) {
		ll s=0, s2=0;
		for(int j=0; j<l; ++j)
			cin >> v[i][j], s+=v[i][j];
		a[i][0]={0, 0, 1};
		for(int j=0, k=1; j<l; ++j) {
			while(s2+n*v[i][j]>=s) {
				a[i][k++]={j, s-s2, n*v[i][j]};
				s2-=s;
			}
			s2+=n*v[i][j];
		}
		b[i]=n;
	}
	array<ll, 3> ls={l, 0, 1};
	for(int i=0; i<n; ++i) {
		int mi=-1;
		for(int j=0; j<n; ++j) {
			while(b[j]&&cmp(ls, a[j][b[j]]))
				--b[j];
			if(b[j]&&(mi==-1||cmp(a[mi][b[mi]-1], a[j][b[j]-1])))
				mi=j;
		}
		a1[i]=ls=a[mi][b[mi]-1];
		b[mi]=0;
		p[i]=mi;
	}
	for(int i=n-2; ~i; --i)
		cout << a1[i][0]*a1[i][2]+a1[i][1] << " " << a1[i][2] << "\n";
	for(int i=n-1; ~i; --i)
		cout << p[i]+1 << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 392 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 3 ms 512 KB Output is correct
22 Correct 3 ms 512 KB Output is correct
23 Correct 2 ms 412 KB Output is correct
24 Correct 3 ms 512 KB Output is correct
25 Correct 2 ms 404 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 392 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 2 ms 460 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 384 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 3 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 2 ms 512 KB Output is correct
29 Correct 3 ms 512 KB Output is correct
30 Correct 2 ms 512 KB Output is correct
31 Correct 3 ms 512 KB Output is correct
32 Correct 2 ms 512 KB Output is correct
33 Correct 3 ms 512 KB Output is correct
34 Correct 2 ms 512 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 3 ms 512 KB Output is correct
37 Correct 3 ms 512 KB Output is correct
38 Correct 2 ms 412 KB Output is correct
39 Correct 3 ms 512 KB Output is correct
40 Correct 2 ms 404 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 3 ms 512 KB Output is correct
43 Correct 40 ms 15992 KB Output is correct
44 Correct 231 ms 78584 KB Output is correct
45 Correct 182 ms 32760 KB Output is correct
46 Correct 21 ms 4224 KB Output is correct
47 Correct 172 ms 50168 KB Output is correct
48 Correct 150 ms 104440 KB Output is correct
49 Correct 56 ms 30072 KB Output is correct
50 Correct 261 ms 126512 KB Output is correct
51 Correct 136 ms 50168 KB Output is correct
52 Correct 272 ms 110200 KB Output is correct
53 Correct 381 ms 103160 KB Output is correct
54 Correct 6 ms 512 KB Output is correct
55 Correct 119 ms 59512 KB Output is correct
56 Correct 247 ms 69496 KB Output is correct
57 Correct 161 ms 60816 KB Output is correct
58 Correct 230 ms 101388 KB Output is correct
59 Correct 176 ms 56056 KB Output is correct
60 Correct 505 ms 147660 KB Output is correct
61 Correct 538 ms 147804 KB Output is correct
62 Correct 552 ms 147564 KB Output is correct
63 Correct 525 ms 147892 KB Output is correct
64 Correct 513 ms 147832 KB Output is correct
65 Correct 417 ms 134488 KB Output is correct
66 Correct 417 ms 134520 KB Output is correct
67 Correct 417 ms 134520 KB Output is correct
68 Correct 206 ms 75128 KB Output is correct
69 Correct 224 ms 68600 KB Output is correct
70 Correct 240 ms 91512 KB Output is correct
71 Correct 329 ms 102136 KB Output is correct