Submission #126941

#TimeUsernameProblemLanguageResultExecution timeMemory
126941mohammedehab2002Naan (JOI19_naan)C++11
24 / 100
4 ms508 KiB
#include <iostream> #include <algorithm> 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 mat[2005][2005],p[2005]; long long sum[2005]; bool ok[2005][2005]; int main() { int n,l; 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]=(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; } } do { bool in=1; for (int i=0;i<n;i++) in&=ok[p[i]][i]; if (in) { for (int i=0;i<n;i++) printf("%d ",p[i]+1); break; } } while (next_permutation(p,p+n)); }

Compilation message (stderr)

naan.cpp: In function 'int main()':
naan.cpp:93: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:93:44: warning: format '%d' expects argument of type 'int', but argument 3 has type 'long long int' [-Wformat=]
naan.cpp:71: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:76: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...