Submission #254054

# Submission time Handle Problem Language Result Execution time Memory
254054 2020-07-29T09:30:10 Z TadijaSebez Naan (JOI19_naan) C++11
100 / 100
703 ms 101240 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ldb long double
const int N=2005;
struct frac{
	ll p,q;
	frac():p(0),q(1){}
	frac(ll a,ll b=1):p(a),q(b){}
	frac operator+(frac b){return frac(p*b.q+b.p*q,q*b.q);}
	bool operator<(frac b){return (ldb)p/q<(ldb)b.p/b.q;}
}p[N][N];
int v[N][N],sum[N],ans[N];
bool was[N];
int main(){
	int n,l;
	scanf("%i %i",&n,&l);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=l;j++){
			scanf("%i",&v[i][j]);
			sum[i]+=v[i][j];
			v[i][j]*=n;
		}
		for(int j=1,ptr=1,take=0;j<=n;j++){
			int need=sum[i];
			while(v[i][ptr]-take<need){
				need-=v[i][ptr]-take;
				take=0;
				ptr++;
			}
			p[i][j]=frac(ptr-1)+frac(take+need,v[i][ptr]);
			take+=need;
		}
	}
	for(int i=1;i<=n;i++){
		frac mn=frac(l+1);
		int k;
		for(int j=1;j<=n;j++)if(!was[j]){
			if(p[j][i]<mn){
				mn=p[j][i];
				k=j;
			}
		}
		if(i!=n)printf("%lld %lld\n",mn.p,mn.q);
		ans[i]=k;
		was[k]=1;
	}
	for(int i=1;i<=n;i++)printf("%i ",ans[i]);
	return 0;
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&l);
  ~~~~~^~~~~~~~~~~~~~~
naan.cpp:20:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%i",&v[i][j]);
    ~~~~~^~~~~~~~~~~~~~~
naan.cpp:45:9: warning: 'k' may be used uninitialized in this function [-Wmaybe-uninitialized]
   ans[i]=k;
   ~~~~~~^~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 63224 KB Output is correct
2 Correct 30 ms 63224 KB Output is correct
3 Correct 30 ms 63224 KB Output is correct
4 Correct 30 ms 63232 KB Output is correct
5 Correct 29 ms 63232 KB Output is correct
6 Correct 28 ms 63232 KB Output is correct
7 Correct 34 ms 63224 KB Output is correct
8 Correct 29 ms 63224 KB Output is correct
9 Correct 34 ms 63232 KB Output is correct
10 Correct 30 ms 63320 KB Output is correct
11 Correct 30 ms 63232 KB Output is correct
12 Correct 31 ms 63232 KB Output is correct
13 Correct 30 ms 63224 KB Output is correct
14 Correct 32 ms 63232 KB Output is correct
15 Correct 45 ms 63224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 63224 KB Output is correct
2 Correct 43 ms 63224 KB Output is correct
3 Correct 30 ms 63360 KB Output is correct
4 Correct 44 ms 63352 KB Output is correct
5 Correct 31 ms 63360 KB Output is correct
6 Correct 35 ms 63224 KB Output is correct
7 Correct 35 ms 63232 KB Output is correct
8 Correct 31 ms 63232 KB Output is correct
9 Correct 32 ms 63352 KB Output is correct
10 Correct 31 ms 63352 KB Output is correct
11 Correct 30 ms 63356 KB Output is correct
12 Correct 29 ms 63232 KB Output is correct
13 Correct 29 ms 63232 KB Output is correct
14 Correct 30 ms 63356 KB Output is correct
15 Correct 30 ms 63352 KB Output is correct
16 Correct 38 ms 63352 KB Output is correct
17 Correct 30 ms 63360 KB Output is correct
18 Correct 30 ms 63352 KB Output is correct
19 Correct 30 ms 63352 KB Output is correct
20 Correct 30 ms 63232 KB Output is correct
21 Correct 33 ms 63352 KB Output is correct
22 Correct 31 ms 63360 KB Output is correct
23 Correct 30 ms 63224 KB Output is correct
24 Correct 31 ms 63232 KB Output is correct
25 Correct 30 ms 63224 KB Output is correct
26 Correct 30 ms 63224 KB Output is correct
27 Correct 31 ms 63352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 63224 KB Output is correct
2 Correct 30 ms 63224 KB Output is correct
3 Correct 30 ms 63224 KB Output is correct
4 Correct 30 ms 63232 KB Output is correct
5 Correct 29 ms 63232 KB Output is correct
6 Correct 28 ms 63232 KB Output is correct
7 Correct 34 ms 63224 KB Output is correct
8 Correct 29 ms 63224 KB Output is correct
9 Correct 34 ms 63232 KB Output is correct
10 Correct 30 ms 63320 KB Output is correct
11 Correct 30 ms 63232 KB Output is correct
12 Correct 31 ms 63232 KB Output is correct
13 Correct 30 ms 63224 KB Output is correct
14 Correct 32 ms 63232 KB Output is correct
15 Correct 45 ms 63224 KB Output is correct
16 Correct 29 ms 63224 KB Output is correct
17 Correct 43 ms 63224 KB Output is correct
18 Correct 30 ms 63360 KB Output is correct
19 Correct 44 ms 63352 KB Output is correct
20 Correct 31 ms 63360 KB Output is correct
21 Correct 35 ms 63224 KB Output is correct
22 Correct 35 ms 63232 KB Output is correct
23 Correct 31 ms 63232 KB Output is correct
24 Correct 32 ms 63352 KB Output is correct
25 Correct 31 ms 63352 KB Output is correct
26 Correct 30 ms 63356 KB Output is correct
27 Correct 29 ms 63232 KB Output is correct
28 Correct 29 ms 63232 KB Output is correct
29 Correct 30 ms 63356 KB Output is correct
30 Correct 30 ms 63352 KB Output is correct
31 Correct 38 ms 63352 KB Output is correct
32 Correct 30 ms 63360 KB Output is correct
33 Correct 30 ms 63352 KB Output is correct
34 Correct 30 ms 63352 KB Output is correct
35 Correct 30 ms 63232 KB Output is correct
36 Correct 33 ms 63352 KB Output is correct
37 Correct 31 ms 63360 KB Output is correct
38 Correct 30 ms 63224 KB Output is correct
39 Correct 31 ms 63232 KB Output is correct
40 Correct 30 ms 63224 KB Output is correct
41 Correct 30 ms 63224 KB Output is correct
42 Correct 31 ms 63352 KB Output is correct
43 Correct 75 ms 66552 KB Output is correct
44 Correct 335 ms 74000 KB Output is correct
45 Correct 238 ms 76152 KB Output is correct
46 Correct 61 ms 65416 KB Output is correct
47 Correct 265 ms 79216 KB Output is correct
48 Correct 155 ms 76152 KB Output is correct
49 Correct 90 ms 69880 KB Output is correct
50 Correct 336 ms 84260 KB Output is correct
51 Correct 221 ms 75128 KB Output is correct
52 Correct 400 ms 83704 KB Output is correct
53 Correct 297 ms 81400 KB Output is correct
54 Correct 30 ms 63352 KB Output is correct
55 Correct 72 ms 69880 KB Output is correct
56 Correct 271 ms 77816 KB Output is correct
57 Correct 205 ms 76024 KB Output is correct
58 Correct 294 ms 80504 KB Output is correct
59 Correct 258 ms 76280 KB Output is correct
60 Correct 689 ms 100856 KB Output is correct
61 Correct 685 ms 100984 KB Output is correct
62 Correct 686 ms 100856 KB Output is correct
63 Correct 670 ms 101240 KB Output is correct
64 Correct 703 ms 101044 KB Output is correct
65 Correct 509 ms 87704 KB Output is correct
66 Correct 483 ms 87672 KB Output is correct
67 Correct 490 ms 87672 KB Output is correct
68 Correct 276 ms 80120 KB Output is correct
69 Correct 343 ms 80728 KB Output is correct
70 Correct 284 ms 82060 KB Output is correct
71 Correct 462 ms 86776 KB Output is correct