# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
131829 |
2019-07-17T18:13:19 Z |
ekrem |
Naan (JOI19_naan) |
C++ |
|
2575 ms |
188920 KB |
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 2005
using namespace std;
typedef long long ll;
typedef pair < ll , ll > ii;
ll n, m, bul, top[N], ans[N], u[N], a[N][N], pre[N][N];
pair < double , ll > b[N][N];
ii c[N][N];
ll gcd(ll x, ll y){
if(!x or !y)
return x + y;
return gcd(y%x, x);
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
scanf("%lld %lld",&n ,&m);
for(ll i = 1; i <= n; i++)
for(ll j = 1; j <= m; j++){
scanf("%lld",&a[i][j]);
top[i] += a[i][j];
a[i][j] *= n;
pre[i][j] = pre[i][j - 1] + a[i][j];
}
for(ll i = 1; i < n; i++){
for(ll j = 1; j <= n; j++){
bul = top[j]*i;
ll ind = upper_bound(pre[j] + 1, pre[j] + m + 1, bul) - pre[j] - 1;
// cout << j << " " << i << " " <<bul << " " << ind << " " << pre[j][ind] << endl;
bul -= pre[j][ind];
ll x = ind*a[j][ind + 1] + bul;
ll y = a[j][ind + 1];
ll gg = gcd(x, y);
x /= gg;y /= gg;
// cout << x << " " << y << endl;
b[i][j] = mp(1.0*x/y, j);
c[i][j] = mp(x, y);
}
sort(b[i] + 1, b[i] + n + 1);
}
for(ll i = 1; i <= n; i++)
b[n][i] = mp(0.0, i);
for(ll i = 1; i <= n; i++){
for(ll j = 1; j <= n; j++){
if(!u[b[i][j].nd]){
ans[i] = b[i][j].nd;
u[ans[i]] = 1;
if(i != n)
printf("%lld %lld\n", c[i][ans[i]].st, c[i][ans[i]].nd);
break;
}
}
}
for(ll i = 1; i <= n; i++)
printf("%lld ", ans[i]);
return 0;
}
Compilation message
naan.cpp: In function 'int main()':
naan.cpp:31: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:34:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld",&a[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 |
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 |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
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 |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
4 ms |
604 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
4 ms |
632 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
4 ms |
632 KB |
Output is correct |
17 |
Correct |
3 ms |
632 KB |
Output is correct |
18 |
Correct |
3 ms |
632 KB |
Output is correct |
19 |
Correct |
3 ms |
632 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
632 KB |
Output is correct |
22 |
Correct |
3 ms |
632 KB |
Output is correct |
23 |
Correct |
2 ms |
376 KB |
Output is correct |
24 |
Correct |
3 ms |
508 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 |
# |
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 |
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 |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
2 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 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 |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
4 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
2 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
4 ms |
632 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
632 KB |
Output is correct |
32 |
Correct |
3 ms |
632 KB |
Output is correct |
33 |
Correct |
3 ms |
632 KB |
Output is correct |
34 |
Correct |
3 ms |
632 KB |
Output is correct |
35 |
Correct |
3 ms |
504 KB |
Output is correct |
36 |
Correct |
3 ms |
632 KB |
Output is correct |
37 |
Correct |
3 ms |
632 KB |
Output is correct |
38 |
Correct |
2 ms |
376 KB |
Output is correct |
39 |
Correct |
3 ms |
508 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 |
204 ms |
23388 KB |
Output is correct |
44 |
Correct |
1292 ms |
107636 KB |
Output is correct |
45 |
Correct |
441 ms |
42580 KB |
Output is correct |
46 |
Correct |
39 ms |
5496 KB |
Output is correct |
47 |
Correct |
745 ms |
68472 KB |
Output is correct |
48 |
Correct |
2195 ms |
146584 KB |
Output is correct |
49 |
Correct |
467 ms |
45644 KB |
Output is correct |
50 |
Correct |
2575 ms |
180016 KB |
Output is correct |
51 |
Correct |
849 ms |
75516 KB |
Output is correct |
52 |
Correct |
2094 ms |
159840 KB |
Output is correct |
53 |
Correct |
1923 ms |
151636 KB |
Output is correct |
54 |
Correct |
3 ms |
504 KB |
Output is correct |
55 |
Correct |
951 ms |
87032 KB |
Output is correct |
56 |
Correct |
1075 ms |
104016 KB |
Output is correct |
57 |
Correct |
897 ms |
91816 KB |
Output is correct |
58 |
Correct |
1645 ms |
149368 KB |
Output is correct |
59 |
Correct |
859 ms |
83576 KB |
Output is correct |
60 |
Correct |
1897 ms |
188920 KB |
Output is correct |
61 |
Correct |
1968 ms |
188640 KB |
Output is correct |
62 |
Correct |
2313 ms |
188152 KB |
Output is correct |
63 |
Correct |
2120 ms |
188792 KB |
Output is correct |
64 |
Correct |
2007 ms |
188744 KB |
Output is correct |
65 |
Correct |
2182 ms |
188628 KB |
Output is correct |
66 |
Correct |
2161 ms |
188820 KB |
Output is correct |
67 |
Correct |
2004 ms |
188792 KB |
Output is correct |
68 |
Correct |
824 ms |
108264 KB |
Output is correct |
69 |
Correct |
767 ms |
97292 KB |
Output is correct |
70 |
Correct |
1063 ms |
131128 KB |
Output is correct |
71 |
Correct |
1228 ms |
142204 KB |
Output is correct |