답안 #126944

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
126944 2019-07-08T16:40:03 Z mohammedehab2002 Naan (JOI19_naan) C++11
0 / 100
256 ms 262148 KB
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
struct frac
{
	long long first,second;
	frac()
	{
		
	}
	frac(long long f,long long s)
	{
		first=f;
		second=s;
	}
	bool operator<(const frac &f) const
	{
		return (first*f.second<second*f.first);
	}
	bool operator<=(const frac &f) const
	{
		return (first*f.second<=second*f.first);
	}
};
int gcd(int a,int b)
{
	if (!a || !b)
	return (a^b);
	return __gcd(a,b);
}
frac norm(frac a)
{
	int g=gcd(a.first,a.second);
	a.first/=g;
	a.second/=g;
	return a;
}
frac operator+(frac a,frac b)
{
	return norm(frac(a.first*b.second+b.first*a.second,a.second*b.second));
}
frac operator-(frac a,frac b)
{
	b.first*=-1;
	return a+b;
}
frac operator*(frac a,frac b)
{
	return norm(frac(a.first*b.first,a.second*b.second));
}
frac operator/(frac a,frac b)
{
	swap(b.first,b.second);
	return a*b;
}
int floor(frac a)
{
	return a.first/a.second;
}
int ceil(frac a)
{
	return (a.first+a.second-1)/a.second;
}
frac sp[2005];
int n,l,mat[2005][2005],p[2005],L[2005],R[2005];
long long sum[2005];
bool ok[2005][2005],vis[2005];
bool match(int node)
{
	for (int i=0;i<n;i++)
	{
		if (ok[node][i] && L[i]==-1)
		{
			L[i]=node;
			R[node]=i;
			return 1;
		}
	}
	for (int i=0;i<n;i++)
	{
		if (ok[node][i] && match(L[i]))
		{
			L[i]=node;
			R[node]=i;
			return 1;
		}
	}
	return 0;
}
int main()
{
	scanf("%d%d",&n,&l);
	for (int i=0;i<n;i++)
	{
		for (int j=1;j<=l;j++)
		{
			scanf("%d",&mat[i][j]);
			sum[j]+=mat[i][j];
		}
	}
	for (int i=1;i<=l;i++)
	sum[i]+=sum[i-1];
	sp[0]=frac(0,1);
	for (int i=1;i<n;i++)
	{
		for (int j=1;j<=l;j++)
		{
			if (frac(i,n)<frac(sum[j],sum[l]))
			{
				sp[i]=(norm(frac(i*sum[l],n))-frac(sum[j-1],1))*frac(1,sum[j]-sum[j-1])+frac(j-1,1);
				break;
			}
		}
		printf("%d %d\n",sp[i].first,sp[i].second);
	}
	sp[n]=frac(l,1);
	for (int i=0;i<n;i++)
	{
		p[i]=i;
		frac tot(0,1);
		for (int j=1;j<=l;j++)
		tot=tot+frac(mat[i][j],1);
		for (int j=0;j<n;j++)
		{
			int l=ceil(sp[j]),r=floor(sp[j+1]);
			frac hap(0,1);
			if (l<=r)
			{
				hap=hap+(frac(l,1)-sp[j])*frac(mat[i][l],1);
				hap=hap+(sp[j+1]-frac(r,1))*frac(mat[i][r+1],1);
				for (int k=l+1;k<=r;k++)
				hap=hap+frac(mat[i][k],1);
			}
			else
			hap=frac(mat[i][l],1)*(sp[j+1]-sp[j]);
			if (frac(1,n)<=hap/tot)
			ok[i][j]=1;
		}
	}
	memset(L,-1,sizeof(L));
	memset(R,-1,sizeof(R));
	int ok=1;
	while (ok--)
	{
		memset(vis,0,sizeof(vis));
		for (int i=0;i<n;i++)
		{
			if (R[i]==-1 && match(i))
			ok=1;
		}
	}
	for (int i=0;i<n;i++)
	printf("%d ",L[i]+1);
}

Compilation message

naan.cpp: In function 'int main()':
naan.cpp:115:44: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%d %d\n",sp[i].first,sp[i].second);
                    ~~~~~~~~~~~             ^
naan.cpp:115:44: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
naan.cpp:93:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&l);
  ~~~~~^~~~~~~~~~~~~~
naan.cpp:98:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d",&mat[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 256 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 4 ms 504 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Runtime error 254 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Runtime error 256 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -