Submission #123845

# Submission time Handle Problem Language Result Execution time Memory
123845 2019-07-02T07:50:01 Z 김현수(#3336) Naan (JOI19_naan) C++14
100 / 100
1022 ms 103304 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll N = 2005;

ll n, m, s[N][N], ans[N];

bool dn[N];

struct frac {
	ll j, m;
	bool operator < (frac &T) {
		if(j / m != T.j / T.m) return j / m < T.j / T.m;
		return (j%m) * T.m < (T.j%T.m) * m;
	}
} x[N][N];

frac get_border (ll I, ll A, ll B) {
	ll S = 0, E = m;
	while(S<E) {
		ll M = (S+E)/2+1;
		s[I][M] * B > A ? E = M-1 : S = M;
	}
	A -= s[I][S] * B;
	frac ret = {A, (s[I][S+1] - s[I][S]) * B};
	return {ret.j + ret.m * S, ret.m};
}

int main()
{
	scanf("%lld%lld",&n,&m);
	for(ll i=1;i<=n;i++) {
		for(ll j=1;j<=m;j++) {
			scanf("%lld",&s[i][j]);
			s[i][j] += s[i][j-1];
		}
		s[i][m+1] = s[i][m] + 1;
		for(ll j=1;j<=n;j++) {
			x[i][j] = get_border(i, j*s[i][m], n);
		}
	}
	for(ll i=1;i<=n;i++) {
		ll I = -1;
		for(ll j=1;j<=n;j++) {
			if(dn[j]) continue;
			if(I == -1 || x[j][i] < x[I][i]) I = j;
		}
		ans[i] = I;
		dn[I] = true;
		if(i != n) printf("%lld %lld\n", x[I][i].j, x[I][i].m);
	}
	for(ll i=1;i<=n;i++) {
		printf("%lld ", ans[i]);
	}
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~
naan.cpp:35:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&s[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~
# 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 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 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 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 376 KB Output is correct
14 Correct 2 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 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 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 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 380 KB Output is correct
19 Correct 3 ms 476 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 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 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 380 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 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 3 ms 376 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 504 KB Output is correct
25 Correct 3 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 376 KB Output is correct
33 Correct 3 ms 380 KB Output is correct
34 Correct 3 ms 476 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 Correct 79 ms 11928 KB Output is correct
44 Correct 466 ms 56264 KB Output is correct
45 Correct 256 ms 28808 KB Output is correct
46 Correct 33 ms 4060 KB Output is correct
47 Correct 329 ms 42588 KB Output is correct
48 Correct 321 ms 75300 KB Output is correct
49 Correct 117 ms 24108 KB Output is correct
50 Correct 578 ms 95600 KB Output is correct
51 Correct 254 ms 41548 KB Output is correct
52 Correct 541 ms 86992 KB Output is correct
53 Correct 434 ms 80964 KB Output is correct
54 Correct 3 ms 376 KB Output is correct
55 Correct 145 ms 44152 KB Output is correct
56 Correct 337 ms 56316 KB Output is correct
57 Correct 271 ms 49448 KB Output is correct
58 Correct 415 ms 78632 KB Output is correct
59 Correct 316 ms 46076 KB Output is correct
60 Correct 1012 ms 96184 KB Output is correct
61 Correct 1016 ms 96032 KB Output is correct
62 Correct 1018 ms 96044 KB Output is correct
63 Correct 1016 ms 96156 KB Output is correct
64 Correct 1022 ms 96204 KB Output is correct
65 Correct 666 ms 103196 KB Output is correct
66 Correct 679 ms 103304 KB Output is correct
67 Correct 731 ms 103160 KB Output is correct
68 Correct 413 ms 60152 KB Output is correct
69 Correct 435 ms 56716 KB Output is correct
70 Correct 484 ms 72120 KB Output is correct
71 Correct 671 ms 81128 KB Output is correct