Submission #673434

# Submission time Handle Problem Language Result Execution time Memory
673434 2022-12-20T15:32:39 Z rainboy Naan (JOI19_naan) C
100 / 100
544 ms 100736 KB
#include <stdio.h>

#define N	2000
#define M	2000

int main() {
	static int ww[N][M + 1], ii[N];
	static long long pp[N][N + 1], qq[N][N + 1];
	int n, m, g, g_, g1, i, i_, i1, j, d, tmp;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		for (j = 1; j <= m; j++) {
			scanf("%d", &ww[i][j]);
			ww[i][j] += ww[i][j - 1];
		}
	for (i = 0; i < n; i++) {
		pp[0][0] = 0, qq[0][0] = 1, pp[0][n] = m, qq[0][n] = 1;
		for (g = 1, j = 0; g < n; g++) {
			while (j < m && (long long) ww[i][j + 1] * n < (long long) ww[i][m] * g)
				j++;
			d = ww[i][j + 1] - ww[i][j];
			pp[i][g] = (long long) j * n * d + (long long) ww[i][m] * g - (long long) ww[i][j] * n, qq[i][g] = n * d;
		}
	}
	for (i = 0; i < n; i++)
		ii[i] = i;
	for (g = 0; g + 1 < n; g++) {
		g1 = g;
		for (g_ = g + 1; g_ < n; g_++) {
			i1 = ii[g1], i_ = ii[g_];
			if (pp[i1][g + 1] / qq[i1][g + 1] > pp[i_][g + 1] / qq[i_][g + 1] || pp[i1][g + 1] / qq[i1][g + 1] == pp[i_][g + 1] / qq[i_][g + 1] && pp[i1][g + 1] % qq[i1][g + 1] * qq[i_][g + 1] > pp[i_][g + 1] % qq[i_][g + 1] * qq[i1][g + 1])
				g1 = g_;
		}
		tmp = ii[g], ii[g] = ii[g1], ii[g1] = tmp;
	}
	for (g = 0; g + 1 < n; g++)
		printf("%lld %lld\n", pp[ii[g]][g + 1], qq[ii[g]][g + 1]);
	for (g = 0; g < n; g++)
		printf("%d ", ii[g] + 1);
	printf("\n");
	return 0;
}

Compilation message

naan.c: In function 'main':
naan.c:32:136: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   32 |    if (pp[i1][g + 1] / qq[i1][g + 1] > pp[i_][g + 1] / qq[i_][g + 1] || pp[i1][g + 1] / qq[i1][g + 1] == pp[i_][g + 1] / qq[i_][g + 1] && pp[i1][g + 1] % qq[i1][g + 1] * qq[i_][g + 1] > pp[i_][g + 1] % qq[i_][g + 1] * qq[i1][g + 1])
      |                                                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
naan.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
naan.c:14:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |    scanf("%d", &ww[i][j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 336 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 0 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 2 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 1 ms 340 KB Output is correct
43 Correct 42 ms 13036 KB Output is correct
44 Correct 286 ms 61020 KB Output is correct
45 Correct 186 ms 26000 KB Output is correct
46 Correct 27 ms 3448 KB Output is correct
47 Correct 223 ms 39108 KB Output is correct
48 Correct 142 ms 71704 KB Output is correct
49 Correct 66 ms 25444 KB Output is correct
50 Correct 308 ms 82932 KB Output is correct
51 Correct 197 ms 37488 KB Output is correct
52 Correct 341 ms 74284 KB Output is correct
53 Correct 238 ms 71140 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 55 ms 48892 KB Output is correct
56 Correct 201 ms 51208 KB Output is correct
57 Correct 164 ms 45464 KB Output is correct
58 Correct 207 ms 70824 KB Output is correct
59 Correct 206 ms 41572 KB Output is correct
60 Correct 544 ms 100484 KB Output is correct
61 Correct 529 ms 100480 KB Output is correct
62 Correct 531 ms 100236 KB Output is correct
63 Correct 479 ms 100736 KB Output is correct
64 Correct 501 ms 100592 KB Output is correct
65 Correct 388 ms 87244 KB Output is correct
66 Correct 388 ms 87236 KB Output is correct
67 Correct 391 ms 87252 KB Output is correct
68 Correct 197 ms 57932 KB Output is correct
69 Correct 237 ms 51724 KB Output is correct
70 Correct 227 ms 68300 KB Output is correct
71 Correct 335 ms 73588 KB Output is correct