제출 #126944

#제출 시각아이디문제언어결과실행 시간메모리
126944mohammedehab2002Naan (JOI19_naan)C++11
0 / 100
256 ms262148 KiB
#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); }

컴파일 시 표준 에러 (stderr) 메시지

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]);
    ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...