답안 #124005

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124005 2019-07-02T10:42:59 Z imyujin Naan (JOI19_naan) C++14
100 / 100
3098 ms 128284 KB
#include<stdio.h>
#include<bitset>

using namespace std;

#define MAXN 2005
#define fi first
#define se second
#define llint __int128_t

typedef long long lint;
typedef pair<lint, lint> pll;

lint V[MAXN][MAXN];
lint Vsum[MAXN][MAXN];
pll X[MAXN][MAXN];
bitset<MAXN> chk;
int P[MAXN];

bool cmp(pll a, pll b) {
	return (llint)a.fi * b.se < (llint)a.se * b.fi;
}

lint ggcd(lint a, lint b) {
	if(a % b == 0) return b;
	return ggcd(b, a % b);
}

pll mkfrac(lint a, lint b) {
	lint g = ggcd(a, b);
	return make_pair(a / g, b / g);
}

int main() {
	int N, L;

	scanf("%d%d", &N, &L);
	for(int i = 0; i < N; i++) for(int j = 0; j < L; j++) scanf("%lld", &V[i][j]);

	for(int i = 0; i < N; i++) {
		Vsum[i][0] = V[i][0];
		for(int j = 1; j < L; j++) Vsum[i][j] = Vsum[i][j - 1] + V[i][j];
	}
	for(int i = 0; i < N; i++) for(int j = 1; j < N; j++) {
		int s = 0, e = L - 1;
		while(s < e) {
			int m = (s + e) / 2;
			//printf("i = %d, m = %d, Vsum[i][m] = %lld\n", i, m, Vsum[i][m]);
			if(Vsum[i][m] * N < Vsum[i][L - 1] * j) s = m + 1;
			else e = m;
		}
		pll left = mkfrac(Vsum[i][s] * N - Vsum[i][L - 1] * j, N * V[i][s]);
		X[i][j] = mkfrac((s + 1) * left.se - left.fi, left.se);
		//printf("i = %d, j = %d, s = %d, left = (%lld, %lld), X[i][j] = (%lld, %lld)\n", i, j, s, left.fi, left.se, X[i][j].fi, X[i][j].se);
	}

	for(int i = 1; i < N; i++) {
		int mn = -1;
		for(int j = 0; j < N; j++) if(!chk[j]) {
			if(mn == - 1 || cmp(X[j][i], X[mn][i])) mn = j;
		}
		printf("%lld %lld\n", X[mn][i].fi, X[mn][i].se);
		chk[mn] = true;
		P[i] = mn;
	}
	for(int i = 1; i < N; i++) printf("%d ", P[i] + 1);
	for(int i = 0; i < N; i++) if(!chk[i]) printf("%d", i + 1);

	return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:37:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &L);
  ~~~~~^~~~~~~~~~~~~~~~
naan.cpp:38:61: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < N; i++) for(int j = 0; j < L; j++) scanf("%lld", &V[i][j]);
                                                        ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 524 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 484 KB Output is correct
18 Correct 3 ms 632 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 4 ms 504 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 504 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 3 ms 348 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 524 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 632 KB Output is correct
25 Correct 3 ms 504 KB Output is correct
26 Correct 3 ms 504 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 3 ms 504 KB Output is correct
30 Correct 3 ms 504 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 484 KB Output is correct
33 Correct 3 ms 632 KB Output is correct
34 Correct 3 ms 504 KB Output is correct
35 Correct 3 ms 504 KB Output is correct
36 Correct 3 ms 632 KB Output is correct
37 Correct 4 ms 504 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 3 ms 504 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 508 KB Output is correct
43 Correct 273 ms 17100 KB Output is correct
44 Correct 1649 ms 73924 KB Output is correct
45 Correct 524 ms 32604 KB Output is correct
46 Correct 41 ms 5104 KB Output is correct
47 Correct 935 ms 49572 KB Output is correct
48 Correct 2578 ms 88092 KB Output is correct
49 Correct 540 ms 30792 KB Output is correct
50 Correct 2984 ms 118384 KB Output is correct
51 Correct 952 ms 54984 KB Output is correct
52 Correct 2394 ms 107408 KB Output is correct
53 Correct 2243 ms 101624 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 1228 ms 50904 KB Output is correct
56 Correct 1295 ms 73452 KB Output is correct
57 Correct 1075 ms 65132 KB Output is correct
58 Correct 2007 ms 98180 KB Output is correct
59 Correct 1035 ms 60632 KB Output is correct
60 Correct 2560 ms 128284 KB Output is correct
61 Correct 2660 ms 128132 KB Output is correct
62 Correct 3044 ms 127736 KB Output is correct
63 Correct 2791 ms 128192 KB Output is correct
64 Correct 2673 ms 128096 KB Output is correct
65 Correct 3098 ms 126924 KB Output is correct
66 Correct 3078 ms 127060 KB Output is correct
67 Correct 2667 ms 126952 KB Output is correct
68 Correct 1106 ms 73656 KB Output is correct
69 Correct 989 ms 69284 KB Output is correct
70 Correct 1410 ms 86980 KB Output is correct
71 Correct 1609 ms 97020 KB Output is correct