Submission #164768

# Submission time Handle Problem Language Result Execution time Memory
164768 2019-11-23T09:27:41 Z maruii Naan (JOI19_naan) C++14
29 / 100
3 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

int N, L;
int P[10], V[10][2001], S[10];
long long A[10], B[10];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> N >> L;
	if (N > 6) assert(0);
	for (int i = 1; i <= N; ++i) {
		for (int j = 1; j <= L; ++j)
			cin >> V[i][j];
		S[i] = accumulate(V[i], V[i] + L + 1, 0);
	}

	iota(P, P + N + 1, 0);

	
	B[0] = 1;
	do {

		bool flag = 1;

		for (int i = 1; i <= N; ++i) {
			int x = P[i];
			int t = (A[i - 1] + B[i - 1] - 1) / B[i - 1];
			long long sum = (t * B[i - 1] - A[i - 1]) * V[x][t];
			if (N * sum >= B[i - 1] * S[x]) {
				A[i] = A[i - 1] * N * V[x][t] + B[i - 1] * S[x];
				B[i] = B[i - 1] * N * V[x][t];
				long long g = __gcd(A[i], B[i]);
				A[i] /= g;
				B[i] /= g;
				continue;
			}
			t++;
			while (t <= L) {
				sum += V[x][t] * B[i - 1];
				if (N * sum >= B[i - 1] * S[x]) break;
				t++;
			}
			if (t > L) {
				flag = 0;
				break;
			}
			B[i] = V[x][t] * N * B[i - 1];
			A[i] = B[i] * t - (N * sum - B[i - 1] * S[x]);
			long long g = __gcd(A[i], B[i]);
			A[i] /= g;
			B[i] /= g;
		}
		if (flag) break;
	} while(next_permutation(P + 1, P + N + 1));

	for (int i = 1; i < N; ++i) printf("%d %d\n", A[i], B[i]);
	for (int i = 1; i <= N; ++i) printf("%d ",P[i]);
	return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:57:58: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  for (int i = 1; i < N; ++i) printf("%d %d\n", A[i], B[i]);
                                                ~~~~      ^
naan.cpp:57:58: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 424 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 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 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 248 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 424 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 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 376 KB Output is correct
10 Correct 3 ms 380 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 380 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 424 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 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 348 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 248 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 424 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 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 376 KB Output is correct
25 Correct 3 ms 380 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 3 ms 376 KB Output is correct
29 Correct 3 ms 380 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 3 ms 376 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 504 KB Output is correct
34 Correct 3 ms 376 KB Output is correct
35 Correct 3 ms 376 KB Output is correct
36 Correct 3 ms 376 KB Output is correct
37 Correct 3 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 3 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 3 ms 376 KB Output is correct
43 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
44 Halted 0 ms 0 KB -