답안 #383203

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383203 2021-03-29T07:56:00 Z ogibogi2004 Naan (JOI19_naan) C++14
100 / 100
1621 ms 118880 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,l;
ll v[2048][2048];
pair<ll,ll> p[2048][2048];
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2)
{
	ll t1=p1.first/p1.second,t2=p2.first/p2.second;
	if(t1!=t2)return t1<t2;
	ll x1=p1.first%p1.second,y1=p1.second;
	ll x2=p2.first%p2.second,y2=p2.second;
	return x1*y2<x2*y1;
}
bool used[2048];
void compress(pair<ll,ll> &p)
{
	ll d=__gcd(p.first,p.second);
	p.first/=d;
	p.second/=d;
}
int main()
{
	cin>>n>>l;
	for(ll i=1;i<=n;++i)
	{
		for(ll j=1;j<=l;++j)
		{
			cin>>v[i][j];
		}
	}
	for(ll i=1;i<=n;++i)
	{
		ll sum=0;
		for(ll j=1;j<=l;++j)
		{
			sum+=v[i][j];
		}
		ll sumv=0,needed;
		ll r=1;
		for(ll j=1;j<n;++j)
		{
			needed=sum*j;
			while(sumv+v[i][r]*n<=needed)
			{
				sumv+=v[i][r]*n;
				++r;
			}
			p[i][j]={(ll)(r-1ll)*v[i][r]*n+needed-sumv,(ll)n*v[i][r]};
			compress(p[i][j]);
		}
	}
	vector<ll>ans;
	for(ll i=1;i<n;++i)
	{
		bool found=0;
		pair<ll,ll> best;
		ll idx;
		for(ll j=1;j<=n;++j)
		{
			if(used[j])continue;
			//cout<<p[j][i].first<<" "<<p[j][i].second<<"   ";
			if(!found||cmp(p[j][i],best))
			{
				best=p[j][i];found=1;
				idx=j;
			}
		}
		cout<<p[idx][i].first<<" "<<p[idx][i].second<<'\n';
		//cout<<endl;
		used[idx]=1;
		ans.push_back(idx);
	}
	for(ll i=1;i<=n;++i)if(!used[i])ans.push_back(i);
	for(auto xd:ans)
	{
		cout<<xd<<" ";
	}
	cout<<'\n';
return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 3 ms 492 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 3 ms 492 KB Output is correct
11 Correct 3 ms 492 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 3 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 3 ms 492 KB Output is correct
17 Correct 3 ms 492 KB Output is correct
18 Correct 3 ms 492 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 4 ms 492 KB Output is correct
21 Correct 3 ms 492 KB Output is correct
22 Correct 3 ms 492 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 364 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 2 ms 364 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 3 ms 492 KB Output is correct
26 Correct 3 ms 492 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 2 ms 364 KB Output is correct
29 Correct 3 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 3 ms 492 KB Output is correct
32 Correct 3 ms 492 KB Output is correct
33 Correct 3 ms 492 KB Output is correct
34 Correct 3 ms 492 KB Output is correct
35 Correct 4 ms 492 KB Output is correct
36 Correct 3 ms 492 KB Output is correct
37 Correct 3 ms 492 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 3 ms 492 KB Output is correct
40 Correct 2 ms 364 KB Output is correct
41 Correct 2 ms 364 KB Output is correct
42 Correct 3 ms 492 KB Output is correct
43 Correct 123 ms 13932 KB Output is correct
44 Correct 774 ms 60652 KB Output is correct
45 Correct 468 ms 30144 KB Output is correct
46 Correct 66 ms 4460 KB Output is correct
47 Correct 555 ms 44012 KB Output is correct
48 Correct 640 ms 77420 KB Output is correct
49 Correct 184 ms 29292 KB Output is correct
50 Correct 970 ms 100844 KB Output is correct
51 Correct 450 ms 41708 KB Output is correct
52 Correct 966 ms 89708 KB Output is correct
53 Correct 783 ms 86364 KB Output is correct
54 Correct 2 ms 364 KB Output is correct
55 Correct 274 ms 51436 KB Output is correct
56 Correct 571 ms 56548 KB Output is correct
57 Correct 461 ms 52332 KB Output is correct
58 Correct 706 ms 86124 KB Output is correct
59 Correct 515 ms 49352 KB Output is correct
60 Correct 1525 ms 118572 KB Output is correct
61 Correct 1539 ms 118468 KB Output is correct
62 Correct 1621 ms 118492 KB Output is correct
63 Correct 1570 ms 118880 KB Output is correct
64 Correct 1550 ms 118544 KB Output is correct
65 Correct 1222 ms 105324 KB Output is correct
66 Correct 1215 ms 105476 KB Output is correct
67 Correct 1139 ms 105196 KB Output is correct
68 Correct 539 ms 67468 KB Output is correct
69 Correct 624 ms 57964 KB Output is correct
70 Correct 634 ms 82540 KB Output is correct
71 Correct 923 ms 87940 KB Output is correct