Submission #383202

# Submission time Handle Problem Language Result Execution time Memory
383202 2021-03-29T07:55:10 Z ogibogi2004 Naan (JOI19_naan) C++14
0 / 100
1 ms 364 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<<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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -